filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.17k stars 450 forks source link

I can not play .wav music. #1

Closed Baron1234 closed 9 years ago

Baron1234 commented 9 years ago

Running FadingSample will throw an exception at CSCore\Codecs\WAV.cs :line 64. when choose .wav music. I am a new learner and don't wha't wrong with this problem, would you known the reason?

filoe commented 9 years ago

There is no WAV.cs file. Post the whole exception including the exception.

garylesueur commented 9 years ago

So I'm having the same/similar problem. the audioClient.StreamLatency is returning 0 and as a result I'm getting an ArgOutOfRangeException when it sets the Latency to 0

System.ArgumentOutOfRangeException was unhandled Message=Specified argument was out of the range of valid values. Parameter name: value ParamName=value Source=CSCore StackTrace: at CSCore.SoundOut.WasapiOut.set_Latency(Int32 value) in C:\dev\cscore\CSCore\SoundOut\WasapiOut.cs:line 176 at CSCore.SoundOut.WasapiOut.InitializeInternal() in C:\dev\cscore\CSCore\SoundOut\WasapiOut.cs:line 570 at CSCore.SoundOut.WasapiOut.Initialize(IWaveSource source) in C:\dev\cscore\CSCore\SoundOut\WasapiOut.cs:line 215 at FadingSample.Program.Main(String[] args) in C:\dev\cscore\Samples\FadingSample\Program.cs:line 36 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

garylesueur commented 9 years ago

It could also be this. Just simply doing

new WaveFileReader(@"wavefile.wav");

In WaveFileReader.ReadChunks:158, the ChunkDataSize comes out as -2088467324

Update: When it reads a datachunk, it appears to not skip the data section and continue trying to read headers. Inverting the condition fixed it.

System.ArgumentOutOfRangeException was unhandled Message=Non-negative number required. Parameter name: value ParamName=value Source=mscorlib StackTrace: at System.IO.FileStream.set_Position(Int64 value) at CSCore.Codecs.WAV.WaveFileReader.ReadChunks(Stream stream) in C:\dev\cscore\CSCore\Codecs\WAV\WaveFileReader.cs:line 158 at CSCore.Codecs.WAV.WaveFileReader..ctor(Stream stream) in C:\dev\cscore\CSCore\Codecs\WAV\WaveFileReader.cs:line 53 at FadingSample.Program.Main(String[] args) in C:\dev\cscore\Samples\FadingSample\Program.cs:line 20 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

filoe commented 9 years ago

Is that wave file issue still reproducible with the latest source? And is there still the problem with the audioclients latency?

filoe commented 9 years ago

Got fixed by pull request from @garylesueur . see #2