0

What is the best array type for audioio.RawSample()?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

What is the best array type for audioio.RawSample()?

by kevinjwalters on Wed Apr 24, 2019 2:23 pm

What is the best array.array type for audioio.RawSample()?

I have been using "h" (signed 16bit integers) as this seems like a natural representation for audio work. However, I've had a glance at the C code under the covers and it looks like it might be copying data around if the signedness does not match the Circuit Playground Express (CPX) DAC which is unsigned? This suggests "H" (unsigned 16bit integers) would be a better choice given no other constraints as this would avoid allocation/copying/deallocation of additional memory buffers? Here's an example of two equivalent samples that can be used with audioio.AudioOut.play()

Code: Select all | TOGGLE FULL SIZE
wave_u = audioio.RawSample(array.array("H", [32768-1000, 32768+1000]))
wave_s = audioio.RawSample(array.array("h", [-1000, 1000]))


Perhaps it (wave_u) is a tad faster too to start playback?

I note adafruit_circuitplayground.express has always used "H" and the example in the library documentation currently uses "h".

kevinjwalters
 
Posts: 489
Joined: Sun Oct 01, 2017 3:15 pm

Re: What is the best array type for audioio.RawSample()?

by tannewt2 on Thu Apr 25, 2019 1:16 pm

You are right. The best thing is to match the signedness of the output. unsigned for the DAC and signed for I2S.

tannewt2
 
Posts: 1443
Joined: Thu Oct 06, 2016 8:48 pm

Re: What is the best array type for audioio.RawSample()?

by kevinjwalters on Thu Apr 25, 2019 2:35 pm

A good tip on I2S. I've not explored external I2S boards for the CPX. Can it drive 2 channel, stereo output that way?

kevinjwalters
 
Posts: 489
Joined: Sun Oct 01, 2017 3:15 pm

Re: What is the best array type for audioio.RawSample()?

by tannewt2 on Fri Apr 26, 2019 2:07 pm

Yup! Stereo should work. (Caveat is that I haven't tested it in a while.)

tannewt2
 
Posts: 1443
Joined: Thu Oct 06, 2016 8:48 pm

Re: What is the best array type for audioio.RawSample()?

by kevinjwalters on Fri Jul 19, 2019 1:28 pm

Stereo works, an M4 board driving x-y oscilloscope with via a 2 channel audioio.Rawsample: PyGamer DACs x-y vector test 3 (YouTube).

kevinjwalters
 
Posts: 489
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.