更新MINI的PCM获取函数名称
This commit is contained in:
@@ -348,12 +348,13 @@ class BOT035(FrameBuffer):
|
|||||||
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
||||||
|
|
||||||
def mic_pga(self, value=None):
|
def mic_pga(self, value=None):
|
||||||
|
'''0:4x, 1:8x, 2:16x, 3:32x, 4:OFF'''
|
||||||
if value is None:
|
if value is None:
|
||||||
return self._rreg(_BOT035_FLAG) >> 4
|
return self._rreg(_BOT035_FLAG) >> 4
|
||||||
else:
|
else:
|
||||||
self._wreg(_BOT035_FLAG, (self._rreg(_BOT035_FLAG) & 0x0F) | (value & 0x03) << 4)
|
self._wreg(_BOT035_FLAG, (self._rreg(_BOT035_FLAG) & 0x0F) | (value & 0x03) << 4)
|
||||||
|
|
||||||
def pcm_power(self, power=None):
|
def pcm_en(self, power=None):
|
||||||
if self._version >= 3:
|
if self._version >= 3:
|
||||||
if power is None:
|
if power is None:
|
||||||
return bool(self._rreg(_BOT035_STA) & 0x08)
|
return bool(self._rreg(_BOT035_STA) & 0x08)
|
||||||
@@ -362,28 +363,28 @@ class BOT035(FrameBuffer):
|
|||||||
else:
|
else:
|
||||||
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
||||||
|
|
||||||
def pcm_state(self, power=None):
|
def pcm_any(self):
|
||||||
return bool(self._rreg(_BOT035_STA) & 0x80)
|
return bool(self._rreg(_BOT035_STA) & 0x80)
|
||||||
|
|
||||||
def pcm_data(self, ibuf=1600):
|
def pcm_read(self, ibuf=1600):
|
||||||
return self._rreg(_BOT035_PCM, ibuf)
|
return self._rreg(_BOT035_PCM, ibuf)
|
||||||
|
|
||||||
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
|
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
|
||||||
if self._version >= 3:
|
if self._version >= 3:
|
||||||
self.pcm_power(True)
|
self.pcm_en(True)
|
||||||
_star = time.ticks_ms()
|
_star = time.ticks_ms()
|
||||||
_size = int(ibuf * seconds * 10)
|
_size = int(ibuf * seconds * 10)
|
||||||
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
|
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(_header)
|
f.write(_header)
|
||||||
while _size > 0:
|
while _size > 0:
|
||||||
if self.pcm_state():
|
if self.pcm_any():
|
||||||
f.write(self.pcm_data(ibuf))
|
f.write(self.pcm_read(ibuf))
|
||||||
_size -= ibuf
|
_size -= ibuf
|
||||||
_star = time.ticks_ms()
|
_star = time.ticks_ms()
|
||||||
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
|
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
|
||||||
raise OSError("Timeout write error")
|
raise OSError("Timeout write error")
|
||||||
self.pcm_power(False)
|
self.pcm_en(False)
|
||||||
else:
|
else:
|
||||||
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user