#๐Ÿ”’ Needing Help with Binary Audio File Streaming

24 messages ยท Page 1 of 1 (latest)

toxic urchin
#

So i have a Project where i basically wanna stream Binary Audio Files via PyAudio in Memory instead of converting it to a .wav File or similiar
Now my Main Issue is the Playback of the File as i just get out nothing output and i am unsure as to what exactly is wrong?
I based my Decoder on this C# Code: https://raw.githubusercontent.com/VitorVilela7/SMW-CodeLib/refs/heads/master/cs/music/BRR.cs
and play the File back via this Code

import pyaudio
import numpy as np

def play_pcm(pcm_data, sample_rate=32000):
    audio = pyaudio.PyAudio()
    stream = audio.open(format=pyaudio.paInt16,
                        channels=1,
                        rate=sample_rate,
                        output=True)
    pcm_bytes = np.array(pcm_data, dtype=np.int16).tobytes()  # Convert PCM data to bytes
    stream.write(pcm_bytes)  # Stream the PCM data
    stream.stop_stream()
    stream.close()
    audio.terminate()

def play_brr_sample(brr_file):
    with open(brr_file, 'rb') as file:
        brr_data = file.read()
    pcm_data = decode_brr(brr_data)
    play_pcm(pcm_data)

def main():
    play_brr_sample("EPiano.brr")

if __name__ == "__main__":
    main()

Here is also the SNES BRR Document: https://snes.nesdev.org/wiki/BRR_samples
also i am still somewhat new to Python but Binary Files are still very confusing to me

SNESdev Wiki

Sound samples played by the S-SMP DSP are stored in the BRR (bit-rate-reduction) data format.
BRR is composed of 16-sample blocks, each of which is stored in 9 bytes of data. This is a 1 byte control block, followed by 8 bytes containing 16 4-bit samples to be decoded (high nibble first).

When a block with the end (E) flag set finishes, the cha...

wind troutBOT
#

@toxic urchin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

storm geyser
#

I don't see the code for decode_brr().

#

@toxic urchin ^^

toxic urchin
#

@storm geyser sorry forgot to upload link :(

#

here you go

#

i do not recieve any error
outside of the usual alsa warning you get with pyaudio
like i used one of the pyaudio examples that plays a sinewave at 44Khz just to see if it was an pyaudio issue but nope

#

the output is just silent sadly

storm geyser
#

Did the sine wave play?

#

Just not your BRR audio data?

toxic urchin
#

also i had to clamp to int16 because else pyaudio would giove me an error

toxic urchin
toxic urchin
#

like i converted my BRR File also via many of the brr to wav programs and these also basically convert it without issue and also play it even tho they play too fast but atleast i lknow that it is not an issue with my brr Sample File

storm geyser
#

So we know:

  • the BRR file is fine (there's some rate-of-play issue but the sound is ok)
  • a test sine wav plays
    so we suspect the brr conversion, or the clamping, or the numpy conversion to bytes
toxic urchin
#

thought so honestly

#

but im sadly not smart enough

#

like i have found thios Program with its SOurce Code but i cannot read C at all

#

but for example it was able to decode the BRR File and Play it succesfully

storm geyser
#

This BRR stuff is fairly complicated.
My audio knowledge isn't great.

I'm bothered by the left shift - it seems like they're shifting 4 bit samples up to 15 bits. That's outside your clip-to-16 stuff. Maybe the samples are 20 bits after the shift, and you're cropping a lot of values to the max vaue (32767) because they're mosting bigger than that.

wind troutBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.