Skip to content

Commit f313dc1

Browse files
committed
change the type of the 1st para of Add from double[] to IEnumerable<double>
1 parent f1e9fe5 commit f313dc1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _"I'm sorry Dave... I'm afraid I can't do that"_
2121
* Source code for the WAV reading method is at the bottom of this page.
2222

2323
```cs
24-
(double[] audio, int sampleRate) = ReadWAV("hal.wav");
24+
(IEnumerable<double> audio, int sampleRate) = ReadWAV("hal.wav");
2525
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 500, maxFreq: 3000);
2626
sg.Add(audio);
2727
sg.SaveImage("hal.png");
@@ -59,7 +59,7 @@ public Form1()
5959

6060
Whenever an audio buffer gets filled, add the data to your Spectrogram:
6161
```cs
62-
private void GotNewBuffer(double[] audio)
62+
private void GotNewBuffer(IEnumerable<double> audio)
6363
{
6464
sg.Add(audio);
6565
}
@@ -81,7 +81,7 @@ Review the source code of the demo application for additional details and consid
8181
This example demonstrates how to convert a MP3 file to a spectrogram image. A sample MP3 audio file in the [data folder](data) contains the audio track from Ken Barker's excellent piano performance of George Frideric Handel's Suite No. 5 in E major for harpsichord ([_The Harmonious Blacksmith_](https://en.wikipedia.org/wiki/The_Harmonious_Blacksmith)). This audio file is included [with permission](dev/Handel%20-%20Air%20and%20Variations.txt), and the [original video can be viewed on YouTube](https://www.youtube.com/watch?v=Mza-xqk770k).
8282

8383
```cs
84-
(double[] audio, int sampleRate) = ReadWAV("song.wav");
84+
(IEnumerable<double> audio, int sampleRate) = ReadWAV("song.wav");
8585

8686
int fftSize = 16384;
8787
int targetWidthPx = 3000;
@@ -117,7 +117,7 @@ Spectrogram (2993, 817)
117117
These examples demonstrate the identical spectrogram analyzed with a variety of different colormaps. Spectrogram colormaps can be changed by calling the `SetColormap()` method:
118118

119119
```cs
120-
(double[] audio, int sampleRate) = ReadWAV("hal.wav");
120+
(IEnumerable<double> audio, int sampleRate) = ReadWAV("hal.wav");
121121
var sg = new SpectrogramGenerator(sampleRate, fftSize: 8192, stepSize: 200, maxFreq: 3000);
122122
sg.Add(audio);
123123
sg.SetColormap(Colormap.Jet);
@@ -141,7 +141,7 @@ Cropped Linear Scale (0-3kHz) | Mel Scale (0-22 kHz)
141141
Amplitude perception in humans, like frequency perception, is logarithmic. Therefore, Mel spectrograms typically display log-transformed spectral power and are presented using Decibel units.
142142

143143
```cs
144-
(double[] audio, int sampleRate) = ReadWAV("hal.wav");
144+
(IEnumerable<double> audio, int sampleRate) = ReadWAV("hal.wav");
145145
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 500, maxFreq: 3000);
146146
sg.Add(audio);
147147

@@ -166,7 +166,7 @@ SFF files be saved using `Complex` data format (with real and imaginary values f
166166
This example creates a spectrogram but saves it using the SFF file format instead of saving it as an image. The SFF file can then be read in any language.
167167

168168
```cs
169-
(double[] audio, int sampleRate) = ReadWAV("hal.wav");
169+
(IEnumerable<double> audio, int sampleRate) = ReadWAV("hal.wav");
170170
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 700, maxFreq: 2000);
171171
sg.Add(audio);
172172
sg.SaveData("hal.sff");
@@ -210,7 +210,7 @@ plt.show()
210210
You should customize your file-reading method to suit your specific application. I frequently use the NAudio package to read data from WAV and MP3 files. This function reads audio data from a mono WAV file and will be used for the examples on this page.
211211

212212
```cs
213-
(double[] audio, int sampleRate) ReadWAV(string filePath, double multiplier = 16_000)
213+
(IEnumerable<double> audio, int sampleRate) ReadWAV(string filePath, double multiplier = 16_000)
214214
{
215215
using var afr = new NAudio.Wave.AudioFileReader(filePath);
216216
int sampleRate = afr.WaveFormat.SampleRate;
@@ -221,6 +221,6 @@ You should customize your file-reading method to suit your specific application.
221221
int samplesRead = 0;
222222
while ((samplesRead = afr.Read(buffer, 0, buffer.Length)) > 0)
223223
audio.AddRange(buffer.Take(samplesRead).Select(x => x * multiplier));
224-
return (audio.ToArray(), sampleRate);
224+
return (audio, sampleRate);
225225
}
226226
```

src/Spectrogram/SpectrogramGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void AddCircular(float[] values) { }
8282
[Obsolete("use the Add() method", true)]
8383
public void AddScroll(float[] values) { }
8484

85-
public void Add(double[] audio, bool process = true)
85+
public void Add(IEnumerable<double> audio, bool process = true)
8686
{
8787
newAudio.AddRange(audio);
8888
if (process)

0 commit comments

Comments
 (0)