I had a minor issue with the existing sound.m in the octave-forge
audio module that was bugging me. When using this function on a
longish array of samples (say, 5min of CD quality audio), there is an
annoying delay before the audio begins to play.
The cause seems to be that clip() is called on the entire array of
samples before writing to the audio device. This patch fixes the
problem by performing the same clip+write procedure in 1 second blocks
of samples rather than all at once.
Hope someone finds this useful.
Roman Stanchak
Index: sound.m
===================================================================
--- sound.m (revision 5480)
+++ sound.m (working copy)
@@ -114,7 +114,15 @@
fwrite(fid, 3, 'int32', 0, 'ieee-be');
fwrite(fid, rate, 'int32', 0, 'ieee-be');
fwrite(fid, channels, 'int32', 0, 'ieee-be');
- fwrite(fid, 32767*clip(data,[-1, 1])', 'int16', 0, 'ieee-be');
+
+ ## write 1s blocks of clipped data
+ nblocks = ceil(size(data, 1)/rate);
+ block_start = 1;
+ for i=1:nblocks,
+ block_end = min(size(data,1), block_start+rate-1);
+ fwrite(fid, 32767*clip(data(block_start:block_end,:),[-1, 1])', 'int16', 0, 'ieee-be');
+ block_start = block_end + 1;
+ end
pclose(fid);
endif
end
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev