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

Stereo >sf not giving correct output file #4

Open
mathiasbredholt opened this issue Feb 3, 2025 · 2 comments
Open

Stereo >sf not giving correct output file #4

mathiasbredholt opened this issue Feb 3, 2025 · 2 comments

Comments

@mathiasbredholt
Copy link

Minimal example

Working - 1 channel

sapf> 800 0 sinosc 1 T "sine" >sfo
wrote file '[...]/sine.wav'  1 channels  1 secs

Gives correct sound file of 1 secs length.

Not working - 2 channels

sapf> 800 2X 0 sinosc 1 T "sine" >sfo
wrote file '[...]/sine.wav'  2 channels  1 secs

Gives sound file of 0.5 secs length. Sounds like every second sample is skipped.

Running v0.1.21 on macOS 15.2.

@lfnoise
Copy link
Owner

lfnoise commented Feb 4, 2025

Problem is here:

@@ -386,7 +386,7 @@ void sfwrite(Thread& th, V& v, Arg filename, bool openIt)
                        minn = std::min(n, minn);
                }
 
-               abl.mBuffers[0].mDataByteSize = minn * sizeof(float);
+               abl.mBuffers[0].mDataByteSize = numChannels * minn * sizeof(float);
                OSStatus err = ExtAudioFileWrite(xaf, minn, &abl);
                if (err) {
                        post("ExtAudioFileWrite failed %d\n", (int)err);

This incorrect code worked for years. My former co-workers at Apple must have fixed a bug and now ExtAudioFile obeys the buffer byte size instead of the number of frames requested in the ExtAudioFileWrite call. I'd think ExtAudioFileWrite should return an error rather than silently write a buffer with a mismatched size.

@mathiasbredholt
Copy link
Author

Yeah that is strange. Works on my side though, after the change.

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