tag:blogger.com,1999:blog-6822536077160579260.post7099764820440039750..comments2023-06-05T14:25:52.227+01:00Comments on Sound Code: Trimming a WAV file using NAudioAnonymoushttp://www.blogger.com/profile/17900587357903273800noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-6822536077160579260.post-547718910075604772014-03-09T22:54:15.568+00:002014-03-09T22:54:15.568+00:00instead of a buffer size of 1024, make sure it is ...instead of a buffer size of 1024, make sure it is sized to a multiple of your WaveFormat.BlockAlign.Anonymoushttps://www.blogger.com/profile/17900587357903273800noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-45479508093192628782014-03-09T22:54:10.311+00:002014-03-09T22:54:10.311+00:00instead of a buffer size of 1024, make sure it is ...instead of a buffer size of 1024, make sure it is sized to a multiple of your WaveFormat.BlockAlign.Anonymoushttps://www.blogger.com/profile/17900587357903273800noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-40493444007518757032014-03-09T10:50:28.941+00:002014-03-09T10:50:28.941+00:00Getting the "Must read complete blocks" ...Getting the "Must read complete blocks" error. Is this due to selecting a bad TimeSpan; or an oddly formed WAV file. My is 13kbps bitrate. I have 63 bytes left.RelevantAdshttps://www.blogger.com/profile/14649839883617352018noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-12363881241994547672014-03-09T10:48:56.338+00:002014-03-09T10:48:56.338+00:00Getting the "Must read complete blocks" ...Getting the "Must read complete blocks" error. Is this due to selecting a bad TimeSpan; or an oddly formed WAV file. My is 13kbps bitrate. I have 63 bytes left.RelevantAdshttps://www.blogger.com/profile/14649839883617352018noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-59461142383876960052012-02-24T11:38:40.194+00:002012-02-24T11:38:40.194+00:00Thanks for the snippet. This worked a treat for me...Thanks for the snippet. This worked a treat for me!<br /><br />I did spot one issue though - there's a rounding error when calculating bytesPerMillisecond. If you change it from an int to a double that should sort it.<br /><br />Also, for what it's worth the 'Must read complete blocks' error is because the data must be read in multiples of reader.WaveFormat.BlockAlign. I had this issue reading a GSM file with a block align of 65, so I set the buffer size to BlockAlign * 100.sodaDreamernoreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-51941063625112582662011-02-25T10:01:25.922+00:002011-02-25T10:01:25.922+00:00what is the value of bytesToRead?what is the value of bytesToRead?Anonymoushttps://www.blogger.com/profile/17900587357903273800noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-82028031399789200162011-02-25T00:51:16.774+00:002011-02-25T00:51:16.774+00:00I have tried to implement this code in Visual Basi...I have tried to implement this code in Visual Basic, but am getting an error <br />"Must read complete blocks" at<br />Dim bytesRead As Integer = reader.Read(buffer, 0, bytesToRead)<br />when invoking as follows:<br /><br /> Sub TrimWavFile(ByVal inPath As String, ByVal outPath As String, _<br /> ByVal cutFromStart As TimeSpan, ByVal cutFromEnd As TimeSpan)<br /> Dim reader As WaveFileReader = New WaveFileReader(inPath)<br /> Dim writer As WaveFileWriter = New WaveFileWriter(outPath)<br /> Dim bytesPerMillisecond As Integer = reader.WaveFormat.AverageBytesPerSecond / 1000<br /> Dim startPos As Integer = cutFromStart.TotalMilliseconds * bytesPerMillisecond<br /> startPos = startPos - startPos Mod reader.WaveFormat.BlockAlign<br /> Dim endBytes As Integer = cutFromEnd.TotalMilliseconds * bytesPerMillisecond<br /> endBytes = endBytes - endBytes Mod reader.WaveFormat.BlockAlign<br /> Dim endPos As Integer = reader.Length - endBytes<br /> TrimWavFile(reader, writer, startPos, endPos)<br /> End Sub<br /><br /> Sub TrimWavFile(ByVal reader As WaveFileReader, ByVal writer As WaveFileWriter, ByVal startPos As Integer, ByVal endPos As Integer)<br /> reader.Position = startPos<br /> Dim buffer(1024) As Byte<br /> While reader.Position < endPos<br /> Dim bytesRequired As Integer = endPos - reader.Position<br /> If bytesRequired > 0 Then<br /> Dim bytesToRead As Integer = Math.Min(bytesRequired, buffer.Length)<br /> Dim bytesRead As Integer = reader.Read(buffer, 0, bytesToRead)<br /> If (bytesRead > 0) Then<br /> writer.WriteData(buffer, 0, bytesRead)<br /> End If<br /> End If<br /> End While<br /> End Sub<br /><br /> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br /> TrimWavFile("F:\VBProjectsDevelopment\3DTrackDisplay1\Sounds\tonovario.wav", _<br /> "F:\VBProjectsDevelopment\3DTrackDisplay1\Sounds\tonovarioShort.wav", _<br /> New TimeSpan(10000000), New TimeSpan(10000000))<br /><br /> End Sub<br /><br />My C# coding level is about 3 out of 10 so maybe I've missed something in the migration.StarTraXhttp://gpsanimator.comnoreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-72153911205351773982010-01-27T18:24:58.525+00:002010-01-27T18:24:58.525+00:00the web server can use NAudio to manipulate audio ...the web server can use NAudio to manipulate audio files, but NAudio cannot be used on the client side in the browserAnonymoushttps://www.blogger.com/profile/17900587357903273800noreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-10398982218272171702010-01-27T08:36:09.403+00:002010-01-27T08:36:09.403+00:00Can we use NAudio for web application..?Can we use NAudio for web application..?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6822536077160579260.post-24311293465353527542009-11-08T23:37:38.308+00:002009-11-08T23:37:38.308+00:00Hello,
Was pleased with this example.
Tried it ou...Hello,<br /><br />Was pleased with this example.<br />Tried it out with NAudio 1.3 (which was totally new to me) and worked perfectly on regular wav disk files.<br /><br />My scenario involed in-memory Waves so I was pleased to see that (apparently starting with 1.3 release) WaveFileReader/Writer did support Streams.<br /><br />Problem is that in the current WaveFileWriter class design, wave header and length is only updated when the object is disposed... which is ok when writing to a file, a little bit less when the stream is from another kind, because we might want to copy the result stream somewhere before disposing it.<br /><br />Correct me if I'm wrong, but I was thinking of copying the block of code that updates the header from the Dispose method into the Flush method. Do you think that could do the job without breaking anything else?<br /><br />UPDATE: Actually I did try this quick fix and it dit it, at least to me. Keep on the good work on this very helpful library.<br /><br />Regards<br />Fredericluckylukehttps://www.blogger.com/profile/00439799290420450484noreply@blogger.com