private void createMixer(int column, MemoryStreamEM sonifiedWAV, float[,] imArr) { int arrNotesLength = imArr.GetLength(0); float[] paramArray = new float[_scanHeight]; for (int i = 0; i < arrNotesLength; i++) { paramArray[i] = imArr[i, column]; } generateColumn(paramArray, column, _myEyeMusic.model.ScanSpeed, sonifiedWAV); }
public MemoryStream createWavMemory(Bitmap bitmap, string name, bool create_img, bool with_cue) { bitmap = managementGUI.resizeImage(bitmap, _scanWidth, _scanHeight, _myEyeMusic.ResizeMode); Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); float[,] imArr = ReconstructColor(bmpData); bitmap.UnlockBits(bmpData); if (create_img) { Bitmap clusteredImage = generatePostClassifictionBitmap(imArr); // display image _myEyeMusic.setScanPictureBoxes(clusteredImage); } MemoryStreamEM sonifiedWAV = new MemoryStreamEM(); MemoryStream toREt = sonifiedWAV.Create(_myEyeMusic.OutDirectory + "\\" + name + ".wav", false, 44100, 16); double volume = _myEyeMusic.MyVolume; if (_myEyeMusic.MyCueType.Equals(eyeMusic2.CueType.NoCue)) { volume = 0.0; } if (with_cue) { short sample; WAVFile cueWAVFile = new WAVFile(); // adding cue cueWAVFile.Open(_myEyeMusic._mapFile + "\\Sounds\\" + _myEyeMusic.model.beep_noise, WAVFile.WAVFileMode.READ); for (int j = 0; j < cueWAVFile.NumSamples; j++) { sample = (short)(volume * cueWAVFile.GetNextSample_16bit()); sample = Math.Min(short.MaxValue, sample); sonifiedWAV.AddSample_16bit(sample); } cueWAVFile.Close(); } for (int i = 0; i < _scanWidth; i++) { createMixer(i, sonifiedWAV, imArr); } sonifiedWAV.addLength(); toREt = sonifiedWAV.mFileStream; return(toREt); }
public void generateColumn(float[] parameterVector, int column, int duration, MemoryStreamEM sonifiedWAV) { int samplesToExtract = (int)(duration * ((double)SampleRate / 1000.0)); int startSample = FirstSample + column * samplesToExtract; int colorNumber = 0; double attenuation = 1.0; int samplesPerColumn = 0; int sampleSum = 0; for (int j = 0; j < samplesToExtract; j++) { sampleSum = 0; samplesPerColumn = 0; for (int i = 0; i < parameterVector.Length; i++) { // Get color number and color attenuation colorNumber = (int)(Math.Floor(Math.Abs(parameterVector[i]))); if (colorNumber >= 5) { colorNumber = 5; } if (colorNumber != 0) // color isn't black { attenuation = ((parameterVector[i]) - colorNumber); // the height of the tone samplesPerColumn++; sampleSum += (int)(attenuation * _samplesArray[calculateWaveIndex(colorNumber, i), j + startSample]); } } sampleSum = (int)((double)sampleSum / (double)Math.Sqrt(samplesPerColumn)); sampleSum = Math.Min(short.MaxValue, sampleSum); sonifiedWAV.AddSample_16bit((short)sampleSum); // Clipping may occur here } }