Exemple #1
0
 /// <summary>
 /// Administer some special effects. Wheee!
 /// </summary>
 /// <param name="effect"></param>
 /// <param name="args"></param>
 /// <param name="data"></param>
 public static void ApplyFX(DSP_FX effect, object[] args, ref WaveFile data)
 {
     double factor;
     switch (effect) {
         case DSP_FX.reverse:
             for (int channel = 0; channel < data.channels; channel++) {
                 Array.Reverse(data.samples[channel]);
             }
             break;
         case DSP_FX.normalize:
             for (int channel = 0; channel < data.channels; channel++) {
                 factor = maxAmplitude(data.samples[channel]) * 1.1;
                 for (int sample = 0; sample < data.samples[channel].Length; sample++) {
                     data.samples[channel][sample] = data.samples[channel][sample] / factor;
                 }
             }
             break;
         case DSP_FX.pitchshift:
             for (int channel = 0; channel < data.channels; channel++) {
                 data.samples[channel] = pitchShift(ref data.samples[channel], data.sampleRate, (int)args[0]);
             }
             break;
         default:
             break;
     }
 }
Exemple #2
0
 public void setWave(WaveFile source)
 {
     wave = source;
     waveform = new WaveFormat(wave.sampleRate, wave.bitDepth, wave.channels);
     pbuffer = wave.getData();
 }
Exemple #3
0
        internal void pasteSelection(int destIndex, WaveFile newWave)
        {
            //TODO: newWave must be resampled to match sampling rate with current sample.
            double[][] result = new double[channels][];
            int i;
            if (destIndex > getNumSamples()) {
                destIndex = getNumSamples();
            }
            int pre = destIndex;
            int mid = newWave.getNumSamples();
            int post = getNumSamples() - destIndex;

            for (i = 0; i < channels; i++) {
                result[i] = new double[pre + mid + post];
            }

            for (int channel = 0; channel < channels; channel++) {
                //fill in pre
                for (i = 0; i < pre; i++) {
                    result[channel][i] = samples[channel][i];
                }
                //fill in mid
                for (i = pre; i < pre + mid; i++) {
                    result[channel][i] = newWave.samples[channel][i - pre];
                }
                //fill in post
                for (i = pre; i < pre + post; i++) {
                    result[channel][i + mid] = samples[channel][i];
                }
            }
            samples = result;
        }
Exemple #4
0
        internal WaveFile copySelection(int start, int end)
        {
            if (!inRange(start) || end <= start) {
                return null;
            }
            if (end > getNumSamples()) {
                end = getNumSamples();
            }
            double[][] duplicate = new double[channels][];
            for (int i = 0; i < channels; i++) {
                duplicate[i] = new double[end - start];
            }

            for (int channel = 0; channel < channels; channel++) {
                Array.Copy(samples[channel], start, duplicate[channel], 0, end - start);
            }

            WaveFile copy = new WaveFile(bitDepth, channels, sampleRate);
            copy.pasteSelection(0, duplicate);
            return copy;
        }
Exemple #5
0
        private void createChildWindow(WaveFile wave)
        {
            WaveForm baby;
            baby = new WaveForm(this, wave);

            children.Add(baby);
            activeChild = baby;
            baby.Show();
            updateWindowMenu();
        }
Exemple #6
0
        private void createChildWindow(string path = null)
        {
            WaveFile wave;
            WaveForm baby;
            if (path == null) {
                wave = new WaveFile();
                baby = new WaveForm(this, wave);
                baby.updateReport("New sine waves generated.");
            } else {
                try {
                    wave = new WaveFile(path);
                    baby = new WaveForm(this, wave);
                    baby.updateReport(wave.getName()+" opened successfully!");
                } catch (Exception e) {
                    MessageBox.Show("Opening Failed: " + e.Message);
                    return;
                }
            }

            children.Add(baby);
            activeChild = baby;
            baby.Show();
            updateWindowMenu();
        }
Exemple #7
0
        public WaveFile getSamples()
        {
            if (recorder.IsAlive) {
                MsgQueue.Add(RecorderMsg.TERMINATING);
                recorder.Join();
            }

            //create a new wave file with the byte array.
            WaveFile result = null;
            if (pSaveBuffer != null && pSaveBuffer.Length > 0) {
                result = new WaveFile(8, 1, 11025, pSaveBuffer);
            }

            return result;
        }