Jump to content
  • 0

MCC172 simultaneous data read and output


Wolfgang_Raspi

Question

Hi,

I'm new to MCC hardware and also programming so sorry if this is either a noob question or has already been solved:
I want to read continuosly data from a accelerometer with a MCC172 and output this data simultaneously and as fast as possible via a USB-audio device. I used the "continuous_scan.py" file as a starting point but I'm getting "Buffer overruns" after a short period of time.

My code looks basically something like this:

p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=8192, output=True)

    while True:
        read_result = hat.a_in_scan_read_numpy(read_request_size, timeout)
        # Check for an overrun error
        if read_result.hardware_overrun:
            print('\n\nHardware overrun\n')
            break
        elif read_result.buffer_overrun:
            print('\n\nBuffer overrun\n')

            stream.stop_stream()
            stream.close()
            p.terminate()  
            print('\n\nStopping Audio Output...\n')
            break
 
        data=read_result.data
        output_bytes = (0.5 * data).tobytes()       
        stream.write(output_bytes)

 

I hope someone can help me with this, thanks!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

The driver is continuously filling an internal buffer from which you request data. Each time you read data, you make room for more. An overrun condition means the buffer is full, and there is no space for new data. To duplicate your condition, I modified the continuous.py example so that every time it read data, it would sleep for 0.5 seconds, and I didn't get an overrun error. If I increased the delay, I did get the error. This tells me you have at least a half second to write data out, which is a lot. So, I suspect your streamwriting is taking too long. The MCC 172 default buffer should be large enough to hold one second of data. You could make the buffer large enough to hold two seconds of data by setting samples_per_channel = 2 * scan_rate. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...