Skip to content

Added CachedSound constructor for playing resource wav files #602

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

YJ15
Copy link

@YJ15 YJ15 commented Feb 28, 2020

Added CachedSound constructor for playing resource wav files
I played the wav file of Properties.Resource using the following source code:

public CachedSound(Stream sound) 
{
        using (var audioFileReader = new WaveFileReader(sound))
        {
            WaveFormat = audioFileReader.WaveFormat;
            var sp = audioFileReader.ToSampleProvider();
            var wholeFile = new List<float>((int)(audioFileReader.Length / 4));
            var sourceSamples = (int)(audioFileReader.Length / (audioFileReader.WaveFormat.BitsPerSample / 8));
            var sampleData = new float[sourceSamples];
            int samplesread;
            while ((samplesread = sp.Read(sampleData, 0, sourceSamples)) > 0)
            {
                wholeFile.AddRange(sampleData.Take(samplesread));
            }
            AudioData = wholeFile.ToArray();                
        }
}

YJ15 added 3 commits February 28, 2020 16:36
Added new CachedSound constructor to play resource streams.
"using System.IO; Is missing"
@YJ15
Copy link
Author

YJ15 commented Feb 28, 2020

"using System.IO;" Is missing.
I fixed this error.

@sampletext32
Copy link

I think it's not good write to a list, it's better to write to a buffer(array) with some offset.

@YJ15
Copy link
Author

YJ15 commented Oct 29, 2021

I think it's not good write to a list, it's better to write to a buffer(array) with some offset.

I create it based on public CachedSound(string audiofilename) in CachedSound.cs.
Since lists are used in the source code, I also used lists.
Why are arrays better than lists?

@jcummings2
Copy link

I needed this change as well, so I adapted it for the new layout in pull request #963.

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

Successfully merging this pull request may close these issues.

3 participants