public SoundDataModel(ILogger <SoundDataModel> logger, IErrorModel errorModel, UserPreferencesModel userPreferencesModel) { _logger = logger; _errorModel = errorModel; _userPreferencesModel = userPreferencesModel; LoadFile.SubscribeAsync(LoadFileImpl); LoadContainer.SubscribeAsync(LoadContainerImpl); CalculateSampleSignalSpectrum.SubscribeAsync(_ => CalculateCommonSignalSpectrumImpl()); GenerateSample.SubscribeAsync(GenerateSampleImp); SetCurrentWorkDirectory.SubscribeAsync(SetCurrentWorkDirectoryImpl); var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); SetCurrentWorkDirectoryImpl(_userPreferencesModel.WorkDirectory ?? currentPath); LoadDefaultData(); }
internal void SetWaveType(WaveType wavetype) { switch (wavetype) { case WaveType.SINE: sampleGenerator = GenerateSineSample; wave = WaveType.SINE; break; case WaveType.TRIANGLE: sampleGenerator = GenerateTriangleSample; wave = WaveType.TRIANGLE; break; case WaveType.SAW: sampleGenerator = GenerateSawSample; wave = WaveType.SAW; break; case WaveType.SQUARE: sampleGenerator = GenerateSquareSample; wave = WaveType.SQUARE; break; case WaveType.WHITE_NOISE: sampleGenerator = GenerateWhiteNoise; wave = WaveType.WHITE_NOISE; break; case WaveType.PINK_NOISE: sampleGenerator = GeneratePinkNoise; wave = WaveType.PINK_NOISE; break; default: break; } }
// Use this for initialization void Start() { frequency = 800; amplitude = 1.0f; sampleGenerator = GenerateSineSample; sampleGenerator2 = GenerateTriangleSample; //referencja do komponentow FMOD - wysokiego poziomu (studio) i niskiego studioSystem = FMODUnity.RuntimeManager.StudioSystem; lowlevelSystem = FMODUnity.RuntimeManager.LowlevelSystem; //odniesienie do glownego kanalu - do niego bedziemy przesylac nasz dzwiek channel = new Channel(); channel1forInstrument = new Channel(); channel2forInstrument = new Channel(); channel3forSoundFile = new Channel(); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroup); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforInstrument); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforInstrument2); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforSoundFile); //inicjalizacja FFT (w FMODzie jako komponent DSP) i linerenderera do wyswietlania equalizera FMODUnity.RuntimeManager.LowlevelSystem.createDSPByType(FMOD.DSP_TYPE.FFT, out fft); fft.setParameterInt((int)FMOD.DSP_FFT.WINDOWTYPE, (int)FMOD.DSP_FFT_WINDOW.HANNING); fft.setParameterInt((int)FMOD.DSP_FFT.WINDOWSIZE, windowSize * 2); lineRendererFFT = gameObject.AddComponent <LineRenderer>(); lineRendererFFT.positionCount = windowSize; lineRendererFFT.startWidth = 0.1f; lineRendererFFT.endWidth = 0.1f; channelGroup.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); //channelGroupforInstrument.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); //channelGroupforInstrument2.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); channelGroupforSoundFile.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); lineRendererSamples = lineRendererHolder.AddComponent <LineRenderer>(); lineRendererSamples.positionCount = sampleRate / 100; lineRendererSamples.startWidth = 0.1f; lineRendererSamples.endWidth = 0.1f; //lowPassFilterGraphMarker = GameObject.CreatePrimitive(PrimitiveType.Cube); //lowPassFilterGraphMarker.transform.position = new Vector3(0, lineRendererSamples.transform.position.y, 0.0f); //lowPassFilterGraphMarker.transform.localScale = new Vector3(0.5f, 5.0f, 0.5f); //lowPassFilterGraphMarker.SetActive(false); //lowPassFilterGraphMarker.GetComponent<Renderer>().material.color = Color.red; //Debug - sprawdzamy czy dobrze udalo nam sie zlapac kanal dzwiekowy (nie mamy jeszcze //obslugi bledow FMOD_OK) uint version; lowlevelSystem.getVersion(out version); bool channelIsPlaying; channel.isPlaying(out channelIsPlaying); UnityEngine.Debug.Log(channelIsPlaying); uint bl; int numbuf; lowlevelSystem.getDSPBufferSize(out bl, out numbuf); UnityEngine.Debug.Log("DSP buffer size is: " + bl + ", " + numbuf); //Wczytujemy i odtwarzamy testowy plik do obiektu 'sound' //Przypisujemy nasz kanal do tej samej grupy co glowny kanal dzwieku FMOD.Sound sound; string nametest = ""; lowlevelSystem.createSound("Assets\\Sounds\\test2.mp3", FMOD.MODE.DEFAULT, out sound); sound.getName(out nametest, 20); UnityEngine.Debug.Log(nametest); InitSampleGeneration(); //debug // (sampleCreated) //{ lowlevelSystem.playSound(generatedSound, channelGroup, true, out channel); channel.setLoopCount(-1); channel.setMode(MODE.LOOP_NORMAL); channel.setPosition(0, TIMEUNIT.MS); channel.setPaused(true); //} //else //{ lowlevelSystem.playSound(sound, channelGroupforSoundFile, true, out channel3forSoundFile); channel3forSoundFile.setLoopCount(-1); channel3forSoundFile.setMode(MODE.LOOP_NORMAL); channel3forSoundFile.setPosition(0, TIMEUNIT.MS); channel3forSoundFile.setPaused(false); //} //lowPassFilterGraphMarker.SetActive(false); InitFilters(); filterApplier.InitFilterApplier(); instrument.InitFilterApplier(); }
public void StartInstrument() { sampleGenerator = GenerateSineSample; sampleGenerator2 = GenerateTriangleSample; StartCatSong(); }