Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

play_wav_from_flash_blocking_reopen #39

Open
brylka787 opened this issue Jan 29, 2025 · 2 comments
Open

play_wav_from_flash_blocking_reopen #39

brylka787 opened this issue Jan 29, 2025 · 2 comments

Comments

@brylka787
Copy link

Hello Mike,

Thonny's picture only shows that the "side-to-side-8k-16bits-stereo.wav"
is in the Pico's flash memory.

But I still have no sound with "play_wav_from_flash_blocking.py".

I took measurements with an oscilloscope.

With "play_tone.py" I have on the pins
pin 18 > 104.2 kHz
pin 17 > 22.05 kHz
pin 16 > 705.6 kHz
And the 440 Hz tone is also very easy to hear.
A bit quiet compared to a test with an ESP32-Cam
and the "PlayMODFromPROGMEMToDAC.ino" from the "ESP8266Audio" library.

With "play_wav_from_flash_blocking.py" I have on the pins
pin 18 > 34.35 kHz
pin 17 > 8.00 kHz
pin 16 > 256.0 kHz
And there is absolutely nothing to hear.
Maybe it is too quiet that I can't hear anything.
I have a pair of PC speakers with an amplifier.

With PC VLC player the "side-to-side-8k-16bits-stereo.wav" can be heard well.

Can you change the volume in the code somehow?
Or somewhere with print to display the data for audio_out = I2S
_ = audio_out.write(wav_samples_mv[:num_read])
.

Peter

@miketeachman
Copy link
Owner

the oscilloscope measurements show that the expected I2S signals are present. It is possible that the 8.0kHz frequency is too low for the I2S hardware. You can try to increase the frequency to see if sound is heard, e.g. SAMPLE_RATE_IN_HZ = 16000

The volume can be increased using the static method I2S.shift(). shift = 1 increases volume by 6dB, shift =2 increases volume by 12 dB. An example on how to use the shift method is shown below.

try:
    while True:
        num_read = wav.readinto(wav_samples_mv)
        # end of WAV file?
        if num_read == 0:
            # end-of-file, advance to first byte of Data section
            _ = wav.seek(44)
        else:
            audio_out.shift(buf=wav_samples_mv, bits=WAV_SAMPLE_SIZE_IN_BITS, shift=1)
            _ = audio_out.write(wav_samples_mv[:num_read])
except (KeyboardInterrupt, Exception) as e:
    print("caught exception {} {}".format(type(e).__name__, e))

@brylka787
Copy link
Author

brylka787 commented Feb 3, 2025

Hello Mike,
I did these tests with an ADC Freenove ES7148.
Everything works very well with ESP32 and a MOD file player.
Then the "play_tone.py" worked with the Pico. But the "play_wav_from_flash_blocking.py" didn't.
I bought a PCM5102A and everything works fine.

Mike, you're a professional. !!!
Today I did a test with the Freenove ES7148
and "play_wav_from_flash_blocking.py".
And I changed the sample frequency from
SAMPLE_RATE_IN_HZ = 8000
to
SAMPLE_RATE_IN_HZ = 16000
I can hear tones on the left and right.

The ES7148 cannot process 8.0kHz.
http://www.everest-semi.com/cn_products.php

Image
Image

Now I can try it out with the volume too.
You can also make the sound quieter using shift. !!!!!!!!
Sorry yes with -2

Thanks
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants