Skip to content

Commit 429426b

Browse files
committed
Further rearrange audio imports
* where possible, check with sys.implementation.version, instead of try/except * reduce overall number of try/except clauses
1 parent 4bc5cfc commit 429426b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

simpleio.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@
2828
* Author(s): Scott Shawcroft
2929
"""
3030
import time
31+
import sys
3132
import array
3233
import digitalio
3334
import pulseio
3435
try:
35-
import audiocore
36-
except ImportError:
37-
try:
36+
# RawSample was moved in CircuitPython 5.x.
37+
if sys.implementation.version[0] >= 5:
38+
import audiocore
39+
else:
3840
import audioio as audiocore
39-
except ImportError:
40-
pass # not always supported by every board!
41-
try:
42-
from audioio import AudioOut
43-
except ImportError:
41+
# Some boards have AudioOut (true DAC), others have PWMAudioOut.
4442
try:
45-
from audiopwmio import PWMAudioOut as AudioOut
43+
from audioio import AudioOut
4644
except ImportError:
47-
pass # not always supported by every board!
45+
from audiopwmio import PWMAudioOut as AudioOut
46+
except ImportError:
47+
pass # not always supported by every board!
4848

4949
def tone(pin, frequency, duration=1, length=100):
5050
"""

0 commit comments

Comments
 (0)