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

AudioReaderFile connot read large file #1175

Open
dfengpo opened this issue Jul 28, 2024 · 2 comments
Open

AudioReaderFile connot read large file #1175

dfengpo opened this issue Jul 28, 2024 · 2 comments

Comments

@dfengpo
Copy link

dfengpo commented Jul 28, 2024

I use AudioReaderFile.Read large file ,it
Throws an exception like this
mmexport1722137499648

@dfengpo dfengpo changed the title AudioReaderFile connt read large file AudioReaderFile connot read large file Jul 28, 2024
@markheath
Copy link
Contributor

An audio file converted to PCM will be many 10s if not hundreds of MB, so not necessarily surprising that it can't be allocated. The recommended way of processing the audio in a file is to work your way through it in buffers (e.g. 1 second of audio at a time)

@dfengpo
Copy link
Author

dfengpo commented Jul 30, 2024

An audio file converted to PCM will be many 10s if not hundreds of MB, so not necessarily surprising that it can't be allocated. The recommended way of processing the audio in a file is to work your way through it in buffers (e.g. 1 second of audio at a time)

How to through it in buffers? like this:

int windowSize = 1048576 * 2000;
byte[] buffer = new byte[windowSize];
long readLiength = 0;
while ((readLiength = await _audioFileReader.ReadAsync(buffer.AsMemory(0, windowSize))) > 0)
{
float[] wavdata = new float[buffer.Length / 4];
Buffer.BlockCopy(buffer, 0, wavdata, 0, buffer.Length);
float[] samples = wavdata.Select((float x) => x * 32768f).ToArray();
result.Add(samples);
buffer = new byte[windowSize];
}

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