├── .github ├── dependabot.yml ├── main.workflow └── workflows │ └── maven.yml ├── .gitignore ├── .travis.yml ├── AndroidManifest.xml ├── README.md ├── pom.xml ├── project.properties └── src ├── main ├── java │ └── org │ │ └── toilelibre │ │ └── libe │ │ └── soundtransform │ │ ├── actions │ │ ├── Action.java │ │ ├── fluent │ │ │ ├── BuildableFluentClientOperation.java │ │ │ ├── BuildableFluentClientOperationReady.java │ │ │ ├── BuildableFluentClientOperationSoundImported.java │ │ │ ├── BuildableFluentClientOperationWithFile.java │ │ │ ├── BuildableFluentClientOperationWithFreqs.java │ │ │ ├── BuildableFluentClientOperationWithInputStream.java │ │ │ ├── BuildableFluentClientOperationWithParallelizedClients.java │ │ │ ├── BuildableFluentClientOperationWithSpectrums.java │ │ │ ├── FluentClient.java │ │ │ ├── FluentClientCommon.java │ │ │ ├── FluentClientInterface.java │ │ │ ├── FluentClientOperation.java │ │ │ ├── FluentClientOperationRunnable.java │ │ │ ├── FluentClientReady.java │ │ │ ├── FluentClientSoundImported.java │ │ │ ├── FluentClientWithFile.java │ │ │ ├── FluentClientWithFreqs.java │ │ │ ├── FluentClientWithInputStream.java │ │ │ ├── FluentClientWithParallelizedClients.java │ │ │ └── FluentClientWithSpectrums.java │ │ ├── notes │ │ │ └── ImportAPackIntoTheLibrary.java │ │ ├── play │ │ │ └── PlaySound.java │ │ ├── record │ │ │ └── RecordSound.java │ │ └── transform │ │ │ ├── AddStreamInfoToInputStream.java │ │ │ ├── AppendSound.java │ │ │ ├── ApplySoundTransform.java │ │ │ ├── ChangeLoudestFreqs.java │ │ │ ├── ChangeSoundFormat.java │ │ │ ├── ConvertFromInputStream.java │ │ │ ├── ConvertToInputStream.java │ │ │ ├── ExportAFile.java │ │ │ └── GetStreamInfo.java │ │ ├── infrastructure │ │ └── service │ │ │ ├── Processor.java │ │ │ ├── appender │ │ │ ├── AppenderAccessor.java │ │ │ ├── ConvertedSoundAppender.java │ │ │ └── ConvertedSoundPitchAndTempoHelper.java │ │ │ ├── audioformat │ │ │ ├── AudioFormatAccessor.java │ │ │ ├── WriteInputStreamToByteArray.java │ │ │ ├── android │ │ │ │ ├── AndroidAudioFileHelper.java │ │ │ │ ├── AndroidAudioFormatAccessor.java │ │ │ │ ├── AndroidConvertProcessor.java │ │ │ │ ├── AndroidWavHelper.java │ │ │ │ ├── AudioInputStream.java │ │ │ │ ├── ByteArrayWithAudioFormatInputStream.java │ │ │ │ ├── HasStreamInfo.java │ │ │ │ ├── NoOpFormatParser.java │ │ │ │ ├── WavOutputStream.java │ │ │ │ └── WavReadableOutputStream.java │ │ │ ├── converter │ │ │ │ ├── AudioFormatConverterAccessor.java │ │ │ │ ├── Converter.java │ │ │ │ ├── ConverterMapping.java │ │ │ │ ├── JorbisCleanConverter.java │ │ │ │ ├── JorbisReadException.java │ │ │ │ ├── MP3JLayerConverter.java │ │ │ │ ├── ProxyConverterLauncher.java │ │ │ │ └── ResultEntry.java │ │ │ └── javax │ │ │ │ ├── JavaxAudioFormatAccessor.java │ │ │ │ ├── JavaxConvertProcessor.java │ │ │ │ ├── JavazoomAudioFileHelper.java │ │ │ │ └── WavAudioFormatParser.java │ │ │ ├── converted │ │ │ └── sound │ │ │ │ └── transforms │ │ │ │ ├── EqualizerSoundTransform.java │ │ │ │ ├── GaussianEqualizerSoundTransform.java │ │ │ │ ├── LevelSoundTransform.java │ │ │ │ ├── LinearRegressionSoundTransform.java │ │ │ │ ├── PralongAndCarlileSoundTransform.java │ │ │ │ ├── PurifySoundTransform.java │ │ │ │ ├── ReduceNoiseSoundTransform.java │ │ │ │ └── SlowdownSoundTransform.java │ │ │ ├── fourier │ │ │ ├── CommonsMath3FourierTransformHelper.java │ │ │ └── FourierAccessor.java │ │ │ ├── frames │ │ │ ├── ByteArrayFrameProcessor.java │ │ │ └── FrameProcessorAccessor.java │ │ │ ├── freqs │ │ │ ├── AdjustFrequenciesToPianoProcessor.java │ │ │ ├── FreqsAccessor.java │ │ │ ├── SimpleChangeOctaveProcessor.java │ │ │ ├── SimpleCompressFrequenciesProcessor.java │ │ │ ├── SimpleFilterFrequenciesProcessor.java │ │ │ ├── SimpleReplaceFrequenciesProcessor.java │ │ │ └── SimpleSurroundInOctaveProcessor.java │ │ │ ├── observer │ │ │ └── Slf4jObserver.java │ │ │ ├── pack │ │ │ ├── GsonPackConfigParser.java │ │ │ ├── GsonPackToStringHelper.java │ │ │ └── PackAccessor.java │ │ │ ├── play │ │ │ ├── android │ │ │ │ ├── AndroidPlayAccessor.java │ │ │ │ └── AndroidPlayObjectProcessor.java │ │ │ └── javax │ │ │ │ ├── JavaxPlayAccessor.java │ │ │ │ └── LineListenerPlayObjectProcessor.java │ │ │ ├── record │ │ │ ├── android │ │ │ │ ├── AndroidRecordAccessor.java │ │ │ │ ├── AndroidRecordSoundProcessor.java │ │ │ │ ├── AndroidRecorderThread.java │ │ │ │ └── TestAudioRecordInitializer.java │ │ │ ├── exporter │ │ │ │ ├── ByteArrayOutputStreamExporter.java │ │ │ │ ├── ByteBufferExporter.java │ │ │ │ └── BytesExportAccessor.java │ │ │ └── javax │ │ │ │ ├── JavaxRecordAccessor.java │ │ │ │ ├── TargetDataLineReaderThread.java │ │ │ │ └── TargetDataLineRecordSoundProcessor.java │ │ │ ├── sound2note │ │ │ ├── CallHPSFrequencyHelper.java │ │ │ ├── MagnitudeADSRHelper.java │ │ │ ├── SoundToNoteAccessor.java │ │ │ ├── android │ │ │ │ ├── AndroidContextLoader.java │ │ │ │ └── AndroidContextLoaderAccessor.java │ │ │ └── javax │ │ │ │ ├── ErrorContextLoader.java │ │ │ │ └── JavaxContextLoaderAccessor.java │ │ │ ├── sound2string │ │ │ ├── GraphSoundToStringHelper.java │ │ │ └── SoundToStringAccessor.java │ │ │ └── spectrum │ │ │ ├── GraphSpectrumToStringHelper.java │ │ │ ├── HPSSpectrumHelper.java │ │ │ ├── NaiveSpectrumToCepstrumHelper.java │ │ │ └── SpectrumAccessor.java │ │ ├── ioc │ │ ├── AllAgnosticAccessorsAndBindings.java │ │ ├── AllServicesAccessors.java │ │ ├── ApplicationInjector.java │ │ ├── ImplAgnosticFinalAccessor.java │ │ ├── ImplAgnosticRootModule.java │ │ ├── ImplChooser.java │ │ ├── RootModuleWithoutAccessor.java │ │ ├── android │ │ │ ├── AndroidFinalAccessor.java │ │ │ └── AndroidRootModule.java │ │ └── javax │ │ │ ├── JavaXRootModule.java │ │ │ └── JavaxFinalAccessor.java │ │ └── model │ │ ├── Service.java │ │ ├── converted │ │ ├── FormatInfo.java │ │ ├── sound │ │ │ ├── CallTransformService.java │ │ │ ├── Channel.java │ │ │ ├── DefaultCallTransformService.java │ │ │ ├── DefaultModifySoundService.java │ │ │ ├── DefaultSoundPitchAndTempoService.java │ │ │ ├── DefaultSoundToStringService.java │ │ │ ├── ModifySoundService.java │ │ │ ├── SegmentedChannel.java │ │ │ ├── SegmentedSound.java │ │ │ ├── Sound.java │ │ │ ├── SoundAccessor.java │ │ │ ├── SoundAppender.java │ │ │ ├── SoundPitchAndTempoHelper.java │ │ │ ├── SoundPitchAndTempoService.java │ │ │ ├── SoundToStringHelper.java │ │ │ ├── SoundToStringService.java │ │ │ └── transform │ │ │ │ ├── AbstractFrequencySoundTransform.java │ │ │ │ ├── AbstractWindowSoundTransform.java │ │ │ │ ├── BlackmanHarrisWindowSoundTransform.java │ │ │ │ ├── CepstrumSoundTransform.java │ │ │ │ ├── CompositeSoundTransform.java │ │ │ │ ├── ComputeMagnitudeSoundTransform.java │ │ │ │ ├── CutSoundTransform.java │ │ │ │ ├── EightBitsSoundTransform.java │ │ │ │ ├── FadeSoundTransform.java │ │ │ │ ├── HammingWindowSoundTransform.java │ │ │ │ ├── HanningWindowSoundTransform.java │ │ │ │ ├── HarmonicProductSpectrumSoundTransform.java │ │ │ │ ├── InsertPartSoundTransform.java │ │ │ │ ├── LoopSoundTransform.java │ │ │ │ ├── MaximumLikelihoodSoundTransform.java │ │ │ │ ├── MixSoundTransform.java │ │ │ │ ├── NoOpSoundTransform.java │ │ │ │ ├── NoOpWindowSoundTransform.java │ │ │ │ ├── NormalizeSoundTransform.java │ │ │ │ ├── PeakFindSoundTransform.java │ │ │ │ ├── PitchSoundTransform.java │ │ │ │ ├── ReplacePartSoundTransform.java │ │ │ │ ├── ReverseSoundTransform.java │ │ │ │ ├── ShapeSoundTransform.java │ │ │ │ ├── SimpleFrequencySoundTransform.java │ │ │ │ ├── SoundToSpectrumsSoundTransform.java │ │ │ │ ├── SoundTransform.java │ │ │ │ ├── SpectrumsToSoundSoundTransform.java │ │ │ │ ├── SpeedUpSoundTransform.java │ │ │ │ ├── SubSoundExtractSoundTransform.java │ │ │ │ ├── ToStringSoundTransform.java │ │ │ │ └── UseWindowFunctionSoundTransform.java │ │ └── spectrum │ │ │ ├── DefaultSpectrumToStringService.java │ │ │ ├── FourierTransformHelper.java │ │ │ ├── Spectrum.java │ │ │ ├── SpectrumAccessor.java │ │ │ ├── SpectrumHelper.java │ │ │ ├── SpectrumToCepstrumHelper.java │ │ │ ├── SpectrumToStringHelper.java │ │ │ └── SpectrumToStringService.java │ │ ├── exception │ │ ├── ErrorCode.java │ │ ├── SoundTransformException.java │ │ └── SoundTransformRuntimeException.java │ │ ├── freqs │ │ ├── AdjustFrequenciesProcessor.java │ │ ├── ChangeOctaveProcessor.java │ │ ├── CompressFrequenciesProcessor.java │ │ ├── DefaultLoudestFreqsService.java │ │ ├── FilterFrequenciesProcessor.java │ │ ├── FreqsAccessor.java │ │ ├── LoudestFreqsService.java │ │ ├── PianoFrequency.java │ │ ├── ReplaceFrequenciesProcessor.java │ │ └── SurroundInRangeProcessor.java │ │ ├── inputstream │ │ ├── AudioFileHelper.java │ │ ├── AudioFileService.java │ │ ├── DefaultAudioFileService.java │ │ ├── InputStreamAccessor.java │ │ ├── StreamInfo.java │ │ ├── convert │ │ │ ├── ConvertAccessor.java │ │ │ ├── ConvertProcessor.java │ │ │ ├── ConverterLauncher.java │ │ │ ├── FormatConvertService.java │ │ │ └── GuessConverterFormatConvertService.java │ │ ├── format │ │ │ ├── AudioFormatParser.java │ │ │ ├── AudioFormatService.java │ │ │ ├── DefaultAudioFormatService.java │ │ │ └── FormatAccessor.java │ │ ├── fromsound │ │ │ ├── DefaultSoundToInputStreamService.java │ │ │ ├── FromSoundAccessor.java │ │ │ └── SoundToInputStreamService.java │ │ └── readsound │ │ │ ├── DefaultInputStreamToSoundService.java │ │ │ ├── FrameProcessor.java │ │ │ ├── InputStreamToByteArrayHelper.java │ │ │ ├── InputStreamToSoundService.java │ │ │ └── ReadSoundAccessor.java │ │ ├── library │ │ ├── Library.java │ │ └── pack │ │ │ ├── AddNoteService.java │ │ │ ├── ContextLoader.java │ │ │ ├── DefaultAddNoteService.java │ │ │ ├── DefaultImportPackService.java │ │ │ ├── ImportPackService.java │ │ │ ├── Pack.java │ │ │ ├── PackAccessor.java │ │ │ ├── PackConfigParser.java │ │ │ ├── PackToStringHelper.java │ │ │ ├── Range.java │ │ │ └── note │ │ │ ├── ADSRHelper.java │ │ │ ├── ComputedChordNote.java │ │ │ ├── ComputedOrganNote.java │ │ │ ├── DefaultSoundToNoteService.java │ │ │ ├── FormulaNote.java │ │ │ ├── FrequencyHelper.java │ │ │ ├── Note.java │ │ │ ├── NoteAccessor.java │ │ │ ├── PureNote.java │ │ │ ├── Silence.java │ │ │ ├── SimpleNote.java │ │ │ ├── SimpleNoteInfo.java │ │ │ ├── SoundToNoteService.java │ │ │ └── TechnicalInstrument.java │ │ ├── logging │ │ ├── AbstractLogAware.java │ │ ├── EventCode.java │ │ ├── LogAware.java │ │ ├── LogEvent.java │ │ ├── Observer.java │ │ └── TextLogEvent.java │ │ ├── play │ │ ├── DefaultPlayObjectService.java │ │ ├── PlayAccessor.java │ │ ├── PlayObjectException.java │ │ ├── PlayObjectProcessor.java │ │ └── PlayObjectService.java │ │ └── record │ │ ├── AmplitudeObserver.java │ │ ├── DefaultRecordSoundService.java │ │ ├── RecordAccessor.java │ │ ├── RecordSoundProcessor.java │ │ ├── RecordSoundService.java │ │ └── exporter │ │ ├── BytesExporterFromThread.java │ │ ├── OutputAsByteArrayOutputStream.java │ │ └── OutputAsByteBuffer.java └── resources │ └── raw │ ├── apiano3.wav │ ├── apiano4.wav │ ├── defaultpack.json │ ├── defaultpackjavax.json │ ├── gpiano1.wav │ ├── gpiano2.wav │ ├── gpiano3.wav │ ├── gpiano4.wav │ ├── gpiano5.wav │ ├── gpiano6.wav │ ├── piano1c.wav │ ├── piano2d.wav │ ├── piano3e.wav │ ├── piano4f.wav │ ├── piano5g.wav │ ├── piano6a.wav │ ├── piano7b.wav │ ├── piano8c.wav │ ├── piano_a.wav │ └── piano_low.wav └── test ├── java └── org │ └── toilelibre │ └── libe │ └── soundtransform │ ├── AudioFormatParserTest.java │ ├── BlackBoxAndroidTest.java │ ├── BlackBoxTest.java │ ├── ByteArrayTest.java │ ├── EqualizerTest.java │ ├── FloatArrayCompressTest.java │ ├── FluentClientAndroidTest.java │ ├── FluentClientTest.java │ ├── FluentClientWeirdInputTest.java │ ├── FormatInfoTest.java │ ├── LoudestFreqsTest.java │ ├── Mp3Test.java │ ├── Pcm2FrameTest.java │ ├── PeakFindClassesScoreTest.java │ ├── PitchAndSpeedHelperTest.java │ ├── RecordTest.java │ ├── SegmentedSoundTest.java │ ├── ShapeTest.java │ ├── Slf4JObserverTest.java │ ├── SlowdownSoundTest.java │ ├── SlowdownTest.java │ ├── SoundToNoteTest.java │ ├── SoundToStringTest.java │ ├── TestDetectNotes.java │ ├── TestLoadWavWithAndroidImpl.java │ ├── TestPlaySound.java │ ├── TestR.java │ ├── TestUpsample.java │ ├── WavTest.java │ ├── WrongPackageAccessorTest.java │ ├── benchmarks │ ├── NotePeakFindBenchmark.java │ └── SoundPeakFindBenchmark.java │ ├── idetests │ ├── ViewCepstrumIDETest.java │ └── ViewSpectrumIDETest.java │ ├── infrastructure │ └── service │ │ ├── audioformat │ │ ├── WriteInputStreamToByteArrayTest.java │ │ ├── android │ │ │ ├── AndroidAudioFileHelperTest.java │ │ │ └── AndroidFileToWavFileConverterTest.java │ │ └── javax │ │ │ ├── JavazoomAudioFileHelperTest.java │ │ │ └── WavAudioFormatParserTest.java │ │ ├── frames │ │ └── ByteArrayFrameProcessorTest.java │ │ ├── play │ │ ├── android │ │ │ └── AndroidPlayObjectProcessorTest.java │ │ └── javax │ │ │ └── JavaxPlayObjectProcessorTest.java │ │ ├── record │ │ ├── android │ │ │ └── AndroidRecordSoundProcessorTest.java │ │ └── javax │ │ │ └── JavaxRecordSoundProcessorTest.java │ │ └── sound2note │ │ └── MagnitudeADSRHelperTest.java │ ├── ioc │ ├── CorrectPackageAccessorTest.java │ ├── ImplChooserTest.java │ ├── SoundTransformAndroidTest.java │ └── SoundTransformTest.java │ └── model │ └── library │ └── pack │ ├── DefaultAddNoteServiceTest.java │ ├── PackToStringHelperTest.java │ └── note │ └── SoundGenerateTest.java └── resources ├── before.wav ├── mp3test.mp3 ├── notamp3file.mp3 ├── raw ├── badidpack.json └── short.ogg ├── smallpack.json └── wrongtechnicalinstrument.json /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "04:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: org.openjdk.jmh:jmh-generator-annprocess 11 | versions: 12 | - "1.28" 13 | - dependency-name: org.openjdk.jmh:jmh-core 14 | versions: 15 | - "1.28" 16 | - dependency-name: org.mockito:mockito-core 17 | versions: 18 | - 3.7.7 19 | - 3.8.0 20 | -------------------------------------------------------------------------------- /.github/main.workflow: -------------------------------------------------------------------------------- 1 | workflow "build" { 2 | resolves = ["GitHub Action for Maven & JDK 14"] 3 | on = "push" 4 | } 5 | 6 | workflow "pull request" { 7 | resolves = ["GitHub Action for Maven & JDK 14"] 8 | on = "pull_request" 9 | } 10 | 11 | action "GitHub Action for Maven & JDK 14" { 12 | uses = "xlui/action-maven-cli/jdk14@master" 13 | args = "test" 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up JDK 14 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 14 16 | - name: Build with Maven 17 | run: mvn -B package --file pom.xml 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | /.project 3 | /.classpath 4 | /.settings/ 5 | /.idea/ 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | /lint.xml 9 | # Package Files # 10 | #*.jar 11 | *.war 12 | *.ear 13 | soundtransform.iml 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | bin/* 18 | /bin/ 19 | /target/ 20 | /gen/ 21 | /res/ 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: android 4 | 5 | android: 6 | components: 7 | # Uncomment the lines below if you want to 8 | # use the latest revision of Android SDK Tools 9 | # - platform-tools 10 | # - tools 11 | 12 | # The BuildTools version used by your project 13 | - build-tools-19.1.0 14 | 15 | # The SDK version used to compile your project 16 | - android-8 17 | 18 | # Additional components 19 | - extra-google-m2repository 20 | - extra-android-m2repository 21 | 22 | # Specify at least one system image, 23 | # if you need to run emulator(s) during your tests 24 | - sys-img-armeabi-v7a-android-19 25 | - sys-img-x86-android-17 26 | 27 | cache: 28 | directories: 29 | - $HOME/.m2/repository 30 | 31 | jdk: 32 | - oraclejdk7 33 | - openjdk7 34 | - openjdk6 35 | - oraclejdk8 36 | 37 | script: 38 | - mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report org.eluder.coveralls:coveralls-maven-plugin:report -DrepoToken=$COVERALLS_TOKEN 39 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # Indicates whether an apk should be generated for each density. 10 | split.density=false 11 | # Project target. 12 | target=android-8 13 | android.library=true 14 | manifest.file=${env.WORK_FOLDER}/AndroidManifest.xml 15 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/Action.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.SOURCE) 7 | @Target(ElementType.TYPE) 8 | public @interface Action { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/BuildableFluentClientOperation.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | public interface BuildableFluentClientOperation extends FluentClientCommon { 4 | 5 | @Override 6 | /** 7 | * Start over the client : reset the state and the value objects nested in 8 | * the client 9 | * 10 | * @return the client, ready to start 11 | */ 12 | BuildableFluentClientOperationReady andAfterStart (); 13 | 14 | /** 15 | * Builds the operation object, makes it ready to be used in the inParallel 16 | * method 17 | * 18 | * @return the client operation 19 | */ 20 | FluentClientOperation build (); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/BuildableFluentClientOperationReady.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | public interface BuildableFluentClientOperationReady extends FluentClientReady, BuildableFluentClientOperation { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/BuildableFluentClientOperationWithFile.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import java.io.File; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | public interface BuildableFluentClientOperationWithFile extends FluentClientWithFile, BuildableFluentClientOperation { 8 | 9 | /** 10 | * Shortcut for importToStream ().importToSound () : Conversion from a File 11 | * to a Sound 12 | * 13 | * @return the client, with a sound imported 14 | * @throws SoundTransformException 15 | * if one of the two import fails 16 | */ 17 | @Override 18 | BuildableFluentClientOperationSoundImported convertIntoSound () throws SoundTransformException; 19 | 20 | /** 21 | * Opens the current file and converts it into an InputStream, ready to be 22 | * read (or to be written to a file) 23 | * 24 | * @return the client, with an inputStream 25 | * @throws SoundTransformException 26 | * the current file is not valid, or the conversion did not work 27 | */ 28 | @Override 29 | BuildableFluentClientOperationWithInputStream importToStream () throws SoundTransformException; 30 | 31 | /** 32 | * Plays the current audio data, converting it temporarily into a sound 33 | * 34 | * @return the client, with a file 35 | * @throws SoundTransformException 36 | * could not play the current audio data 37 | */ 38 | @Override 39 | BuildableFluentClientOperationWithFile playIt () throws SoundTransformException; 40 | 41 | /** 42 | * Stops the client pipeline and returns the obtained file 43 | * 44 | * @return a file 45 | */ 46 | @Override 47 | File stopWithFile (); 48 | 49 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/BuildableFluentClientOperationWithParallelizedClients.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public interface BuildableFluentClientOperationWithParallelizedClients extends FluentClientWithParallelizedClients, BuildableFluentClientOperation { 6 | 7 | /** 8 | * Uses the sounds inside the nested clients to mix them all and to produce 9 | * a single sound 10 | * 11 | * @return the client, with a sound imported 12 | * @throws SoundTransformException 13 | * if the nested clients are not in the Sound imported state 14 | */ 15 | @Override 16 | BuildableFluentClientOperationSoundImported mixAllInOneSound () throws SoundTransformException; 17 | 18 | /** 19 | * Stops the client pipeline and gets all the values inside each nested 20 | * client 21 | * 22 | * @param resultClass 23 | * You have to specify what type of result you expect. the value 24 | * can be one of this list : (Sound.class, InputStream.class, 25 | * File.class, String.class, float [].class) 26 | * 27 | * @param 28 | * the array component type of the returned value 29 | * 30 | * @return an array of results 31 | */ 32 | @Override 33 | T [] stopWithResults (Class resultClass); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/FluentClientCommon.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import org.toilelibre.libe.soundtransform.model.library.pack.Pack; 4 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 5 | 6 | public interface FluentClientCommon { 7 | 8 | /** 9 | * Start over the client : reset the state and the value objects nested in 10 | * the client 11 | * 12 | * @return the client, ready to start 13 | */ 14 | FluentClientReady andAfterStart (); 15 | 16 | /** 17 | * Stops the client pipeline and returns the pack whose title is in 18 | * parameter 19 | * 20 | * @param title 21 | * the title of the pack 22 | * @return a pack object 23 | */ 24 | Pack stopWithAPack (String title); 25 | 26 | /** 27 | * Stops the client pipeline and returns the currently subscribed observers 28 | * 29 | * @return the observers 30 | */ 31 | Observer [] stopWithObservers (); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/FluentClientOperationRunnable.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import org.toilelibre.libe.soundtransform.actions.fluent.FluentClientOperation.Step; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformRuntimeException; 6 | 7 | public class FluentClientOperationRunnable implements Runnable { 8 | 9 | private final FluentClientOperation operation; 10 | private final FluentClientInterface clientInterface; 11 | private final int clientId; 12 | 13 | public FluentClientOperationRunnable (final FluentClientOperation operation1, final FluentClientInterface clientInterface1, final int clientId1) { 14 | this.operation = operation1; 15 | this.clientInterface = clientInterface1; 16 | this.clientId = clientId1; 17 | } 18 | 19 | @Override 20 | public void run () { 21 | for (final Step step : this.operation.getSteps ()) { 22 | try { 23 | step.run (this.clientInterface, this.clientId); 24 | } catch (final SoundTransformException ste) { 25 | throw new SoundTransformRuntimeException (ste); 26 | } 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/FluentClientWithFile.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import java.io.File; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | public interface FluentClientWithFile extends FluentClientCommon { 8 | 9 | /** 10 | * Shortcut for importToStream ().importToSound () : Conversion from a File 11 | * to a Sound 12 | * 13 | * @return the client, with a sound imported 14 | * @throws SoundTransformException 15 | * if one of the two import fails 16 | */ 17 | FluentClientSoundImported convertIntoSound () throws SoundTransformException; 18 | 19 | /** 20 | * Opens the current file and convert it into an InputStream, ready to be 21 | * read (or to be written to a file) 22 | * 23 | * @return the client, with an inputStream 24 | * @throws SoundTransformException 25 | * the current file is not valid, or the conversion did not work 26 | */ 27 | FluentClientWithInputStream importToStream () throws SoundTransformException; 28 | 29 | /** 30 | * Plays the current audio data and convert it temporarily into a sound 31 | * 32 | * @return the client, with a file 33 | * @throws SoundTransformException 34 | * could not play the current audio data 35 | */ 36 | FluentClientWithFile playIt () throws SoundTransformException; 37 | 38 | /** 39 | * Stops the client pipeline and returns the obtained file 40 | * 41 | * @return a file 42 | */ 43 | File stopWithFile (); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/fluent/FluentClientWithParallelizedClients.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.fluent; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public interface FluentClientWithParallelizedClients extends FluentClientCommon { 6 | 7 | /** 8 | * Uses the sounds inside the nested clients to mix them all and to produce 9 | * a single sound 10 | * 11 | * @return the client, with a sound imported 12 | * @throws SoundTransformException 13 | * if the nested clients are not in the Sound imported state 14 | */ 15 | FluentClientSoundImported mixAllInOneSound () throws SoundTransformException; 16 | 17 | /** 18 | * Stops the client pipeline and get all the values inside each nested 19 | * client 20 | * 21 | * @param resultClass 22 | * You have to specify what type of result you expect. the value 23 | * can be one of this list : (Sound.class, InputStream.class, 24 | * File.class, String.class, float [].class) 25 | * 26 | * @param 27 | * the array component type of the returned value 28 | * 29 | * @return an array of results 30 | */ 31 | T [] stopWithResults (Class resultClass); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/notes/ImportAPackIntoTheLibrary.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.notes; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.library.Library; 9 | import org.toilelibre.libe.soundtransform.model.library.pack.ImportPackService; 10 | import org.toilelibre.libe.soundtransform.model.library.pack.Pack; 11 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 12 | 13 | @Action 14 | public class ImportAPackIntoTheLibrary { 15 | 16 | private final ImportPackService importPack; 17 | private final Library library; 18 | 19 | public ImportAPackIntoTheLibrary (final Observer... observers) { 20 | this.importPack = (ImportPackService) ApplicationInjector.$.select (ImportPackService.class).setObservers (observers); 21 | this.library = ApplicationInjector.$.select (Library.class); 22 | } 23 | 24 | public Pack getPack (final String title) { 25 | return this.importPack.getAPack (this.library, title); 26 | } 27 | 28 | public void importAPack (final String title, final InputStream jsonStream) throws SoundTransformException { 29 | this.importPack.importPack (this.library, title, jsonStream); 30 | } 31 | 32 | public void importAPack (final String title, final Object context, final Class rClass, final int packJsonId) throws SoundTransformException { 33 | this.importPack.importPack (this.library, title, context, rClass, packJsonId); 34 | 35 | } 36 | 37 | public void importAPack (final String title, final String jsonContent) throws SoundTransformException { 38 | this.importPack.importPack (this.library, title, jsonContent); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/play/PlaySound.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.play; 2 | 3 | import java.io.InputStream; 4 | import java.io.Serializable; 5 | 6 | import org.toilelibre.libe.soundtransform.actions.Action; 7 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 9 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 10 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 11 | import org.toilelibre.libe.soundtransform.model.play.PlayObjectService; 12 | 13 | @Action 14 | public class PlaySound { 15 | 16 | private final PlayObjectService playSound; 17 | 18 | public PlaySound () { 19 | this.playSound = ApplicationInjector.$.select (PlayObjectService.class); 20 | } 21 | 22 | public void play (final InputStream is, final Object stopMonitor, final int skipMilliSeconds) throws SoundTransformException { 23 | this.playSound.play (is, stopMonitor, skipMilliSeconds); 24 | } 25 | 26 | public void play (final Sound sound, final Object stopMonitor, final int skipMilliSeconds) throws SoundTransformException { 27 | this.playSound.play (sound, stopMonitor, skipMilliSeconds); 28 | } 29 | 30 | @SuppressWarnings ("unchecked") 31 | public void play (final Spectrum spectrum1, final Object stopMonitor, int skipMilliSeconds) throws SoundTransformException { 32 | final Spectrum spectrum = (Spectrum) spectrum1; 33 | ((PlayObjectService) this.playSound).play (spectrum, stopMonitor, skipMilliSeconds); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/record/RecordSound.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.record; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 8 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 10 | import org.toilelibre.libe.soundtransform.model.record.AmplitudeObserver; 11 | import org.toilelibre.libe.soundtransform.model.record.RecordSoundService; 12 | 13 | @Action 14 | public class RecordSound { 15 | 16 | private final RecordSoundService recordSound; 17 | 18 | public RecordSound () { 19 | this.recordSound = ApplicationInjector.$.select (RecordSoundService.class); 20 | } 21 | 22 | public InputStream recordRawInputStream (final StreamInfo streamInfo, final Object stop) throws SoundTransformException { 23 | return this.recordSound.recordRawInputStream (streamInfo, stop); 24 | } 25 | 26 | public InputStream recordLimitedTimeRawInputStream (final StreamInfo streamInfo) throws SoundTransformException { 27 | return this.recordSound.recordLimitedTimeRawInputStream (streamInfo); 28 | } 29 | 30 | public Sound startRecordingASound (final StreamInfo streamInfo, final AmplitudeObserver amplitudeObserver, final Object stop) throws SoundTransformException { 31 | return this.recordSound.startRecordingASound (streamInfo, amplitudeObserver, stop); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/AddStreamInfoToInputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.AudioFileService; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 10 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 11 | 12 | @Action 13 | public final class AddStreamInfoToInputStream { 14 | 15 | private final AudioFileService audioFile; 16 | 17 | public AddStreamInfoToInputStream (final Observer... observers) { 18 | this.audioFile = (AudioFileService) ApplicationInjector.$.select (AudioFileService.class).setObservers (observers); 19 | } 20 | 21 | public InputStream transformRawInputStream (final InputStream ais, final StreamInfo isi) throws SoundTransformException { 22 | return this.audioFile.streamFromRawStream (ais, isi); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/AppendSound.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.actions.Action; 4 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.ModifySoundService; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | 9 | @Action 10 | public final class AppendSound { 11 | 12 | private final ModifySoundService modifySound; 13 | 14 | public AppendSound () { 15 | this.modifySound = ApplicationInjector.$.select (ModifySoundService.class); 16 | } 17 | 18 | public Sound append (final Sound sound1, final Sound sound2) throws SoundTransformException { 19 | return this.modifySound.append (sound1, sound2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ApplySoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.actions.Action; 4 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.CallTransformService; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SoundTransform; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 9 | 10 | @Action 11 | public final class ApplySoundTransform { 12 | 13 | private final CallTransformService callTransform; 14 | 15 | public ApplySoundTransform (final Observer... observers) { 16 | this.callTransform = (CallTransformService) ApplicationInjector.$.select (CallTransformService.class).setObservers (observers); 17 | } 18 | 19 | public U [] apply (final T [] input, final SoundTransform transform) throws SoundTransformException { 20 | return this.callTransform.apply (input, transform); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ChangeLoudestFreqs.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.util.List; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.freqs.LoudestFreqsService; 9 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 10 | 11 | @Action 12 | public final class ChangeLoudestFreqs { 13 | 14 | private final LoudestFreqsService loudestFreqs; 15 | 16 | public ChangeLoudestFreqs (final Observer... observers) { 17 | this.loudestFreqs = ApplicationInjector.$.select (LoudestFreqsService.class); 18 | } 19 | 20 | public List adjust (final List freqs) { 21 | return this.loudestFreqs.adjust (freqs); 22 | } 23 | 24 | public List compress (final List freqs, final float factor) { 25 | return this.loudestFreqs.compress (freqs, factor); 26 | } 27 | 28 | public List filterRange (final List freqs, final float low, final float high) throws SoundTransformException { 29 | return this.loudestFreqs.filterRange (freqs, low, high); 30 | } 31 | 32 | public List insertPart (final List freqs, final List subFreqs, final int start) { 33 | return this.loudestFreqs.insertPart (freqs, subFreqs, start); 34 | } 35 | 36 | public List octaveDown (final List freqs) { 37 | return this.loudestFreqs.octaveDown (freqs); 38 | } 39 | 40 | public List octaveUp (final List freqs) { 41 | return this.loudestFreqs.octaveUp (freqs); 42 | } 43 | 44 | public List replacePart (final List freqs, final List subFreqs, final int start) { 45 | return this.loudestFreqs.replacePart (freqs, subFreqs, start); 46 | } 47 | 48 | public List surroundInRange (final List freqs, final float low, final float high) throws SoundTransformException { 49 | return this.loudestFreqs.surroundInRange (freqs, low, high); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ChangeSoundFormat.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.actions.Action; 4 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 5 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.ModifySoundService; 7 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 8 | 9 | @Action 10 | public class ChangeSoundFormat { 11 | 12 | private final ModifySoundService modifySound; 13 | 14 | public ChangeSoundFormat () { 15 | this.modifySound = ApplicationInjector.$.select (ModifySoundService.class); 16 | } 17 | 18 | public Sound changeFormat (final Sound input, final FormatInfo formatInfo) { 19 | return this.modifySound.changeFormat (input, formatInfo); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ConvertFromInputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 8 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 10 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.InputStreamToSoundService; 11 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 12 | 13 | @Action 14 | public final class ConvertFromInputStream { 15 | 16 | private final InputStreamToSoundService is2Sound; 17 | 18 | public ConvertFromInputStream (final Observer... observers) { 19 | this.is2Sound = (InputStreamToSoundService) ApplicationInjector.$.select (InputStreamToSoundService.class).setObservers (observers); 20 | } 21 | 22 | public Sound fromInputStream (final InputStream ais) throws SoundTransformException { 23 | return this.is2Sound.fromInputStream (ais); 24 | } 25 | 26 | public Sound fromInputStream (final InputStream ais, final StreamInfo isInfo) throws SoundTransformException { 27 | return this.is2Sound.fromInputStream (ais, isInfo); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ConvertToInputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.io.File; 4 | import java.io.InputStream; 5 | 6 | import org.toilelibre.libe.soundtransform.actions.Action; 7 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | import org.toilelibre.libe.soundtransform.model.inputstream.AudioFileService; 11 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 12 | import org.toilelibre.libe.soundtransform.model.inputstream.fromsound.SoundToInputStreamService; 13 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 14 | 15 | @Action 16 | public final class ConvertToInputStream { 17 | 18 | private final AudioFileService audioFile; 19 | private final SoundToInputStreamService sound2is; 20 | 21 | public ConvertToInputStream (final Observer... observers) { 22 | this.audioFile = (AudioFileService) ApplicationInjector.$.select (AudioFileService.class).setObservers (observers); 23 | this.sound2is = (SoundToInputStreamService) ApplicationInjector.$.select (SoundToInputStreamService.class).setObservers (observers); 24 | } 25 | 26 | public InputStream toStream (final File fOrigin) throws SoundTransformException { 27 | return this.audioFile.streamFromFile (fOrigin); 28 | } 29 | 30 | public InputStream toStream (final Sound sound, final StreamInfo streamInfo) throws SoundTransformException { 31 | return this.sound2is.toStream (sound, streamInfo); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/ExportAFile.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.io.File; 4 | import java.io.InputStream; 5 | 6 | import org.toilelibre.libe.soundtransform.actions.Action; 7 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 8 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.AudioFileService; 10 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 11 | 12 | @Action 13 | public final class ExportAFile { 14 | 15 | private final AudioFileService audioFile; 16 | 17 | public ExportAFile (final Observer... observers) { 18 | this.audioFile = (AudioFileService) ApplicationInjector.$.select (AudioFileService.class).setObservers (observers); 19 | } 20 | 21 | public void writeFile (final InputStream is, final File fDest) throws SoundTransformException { 22 | this.audioFile.fileFromStream (is, fDest); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/actions/transform/GetStreamInfo.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.actions.transform; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.actions.Action; 6 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.InputStreamToSoundService; 10 | import org.toilelibre.libe.soundtransform.model.logging.Observer; 11 | 12 | @Action 13 | public class GetStreamInfo { 14 | 15 | private final InputStreamToSoundService is2Sound; 16 | 17 | public GetStreamInfo (final Observer... observers) { 18 | this.is2Sound = (InputStreamToSoundService) ApplicationInjector.$.select (InputStreamToSoundService.class).setObservers (observers); 19 | } 20 | 21 | public StreamInfo getStreamInfo (final InputStream ais) throws SoundTransformException { 22 | return this.is2Sound.getStreamInfo (ais); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/Processor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.SOURCE) 7 | @Target(ElementType.TYPE) 8 | public @interface Processor { 9 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/appender/AppenderAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.appender; 2 | 3 | import org.toilelibre.libe.soundtransform.ioc.AllServicesAccessors; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.SoundAppender; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.SoundPitchAndTempoHelper; 6 | 7 | public abstract class AppenderAccessor extends AllServicesAccessors { 8 | 9 | protected SoundAppender provideSoundAppender () { 10 | return new ConvertedSoundAppender (); 11 | } 12 | 13 | protected SoundPitchAndTempoHelper provideSoundPitchAndTempoHelper () { 14 | return new ConvertedSoundPitchAndTempoHelper (); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/AudioFormatAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.appender.AppenderAccessor; 4 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.InputStreamToByteArrayHelper; 5 | 6 | public abstract class AudioFormatAccessor extends AppenderAccessor { 7 | 8 | protected InputStreamToByteArrayHelper provideInputStreamToByteArrayHelper () { 9 | return new WriteInputStreamToByteArray (); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/WriteInputStreamToByteArray.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 8 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.InputStreamToByteArrayHelper; 11 | 12 | @Processor 13 | final class WriteInputStreamToByteArray implements InputStreamToByteArrayHelper { 14 | 15 | enum WriteInputStreamToByteArrayErrorCode implements ErrorCode { 16 | 17 | ERROR_WHILE_READING_STREAM ("System error while reading stream"); 18 | 19 | private final String messageFormat; 20 | 21 | WriteInputStreamToByteArrayErrorCode (final String mF) { 22 | this.messageFormat = mF; 23 | } 24 | 25 | @Override 26 | public String getMessageFormat () { 27 | return this.messageFormat; 28 | } 29 | } 30 | 31 | WriteInputStreamToByteArray () { 32 | 33 | } 34 | 35 | @Override 36 | public byte [] convertToByteArray (final InputStream inputStream) throws SoundTransformException { 37 | final DataInputStream dataInputStream = new DataInputStream (inputStream); 38 | byte [] byteArray; 39 | try { 40 | byteArray = new byte [dataInputStream.available ()]; 41 | dataInputStream.read (byteArray); 42 | return byteArray; 43 | } catch (final IOException e) { 44 | throw new SoundTransformException (WriteInputStreamToByteArrayErrorCode.ERROR_WHILE_READING_STREAM, e, inputStream.toString ()); 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/AndroidAudioFormatAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import org.toilelibre.libe.soundtransform.ioc.AllAgnosticAccessorsAndBindings; 4 | import org.toilelibre.libe.soundtransform.model.inputstream.AudioFileHelper; 5 | import org.toilelibre.libe.soundtransform.model.inputstream.convert.ConvertProcessor; 6 | import org.toilelibre.libe.soundtransform.model.inputstream.format.AudioFormatParser; 7 | 8 | public abstract class AndroidAudioFormatAccessor extends AllAgnosticAccessorsAndBindings { 9 | 10 | @Override 11 | protected AudioFileHelper provideAudioFileHelper () { 12 | return new AndroidAudioFileHelper (); 13 | } 14 | 15 | @Override 16 | protected AudioFormatParser provideAudioFormatParser () { 17 | return new NoOpFormatParser (); 18 | } 19 | 20 | @Override 21 | protected ConvertProcessor provideConvertProcessor () { 22 | return new AndroidConvertProcessor (); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/ByteArrayWithAudioFormatInputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import java.io.ByteArrayInputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 6 | 7 | final class ByteArrayWithAudioFormatInputStream extends ByteArrayInputStream implements HasStreamInfo { 8 | 9 | private final StreamInfo info; 10 | 11 | public ByteArrayWithAudioFormatInputStream (final byte [] buf, final StreamInfo info1) { 12 | super (buf); 13 | this.info = info1; 14 | } 15 | 16 | public byte [] getAllContent () { 17 | return this.buf.clone (); 18 | } 19 | 20 | @Override 21 | public StreamInfo getInfo () { 22 | return this.info; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/HasStreamInfo.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 4 | 5 | interface HasStreamInfo { 6 | StreamInfo getInfo (); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/NoOpFormatParser.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.format.AudioFormatParser; 10 | 11 | @Processor 12 | final class NoOpFormatParser implements AudioFormatParser { 13 | 14 | @Override 15 | public Object audioFormatfromStreamInfo (final StreamInfo info) { 16 | return info; 17 | } 18 | 19 | @Override 20 | public StreamInfo fromAudioFormat (final Object audioFormat1, final long l) { 21 | return (StreamInfo) audioFormat1; 22 | } 23 | 24 | @Override 25 | public StreamInfo getStreamInfo (final InputStream is) throws SoundTransformException { 26 | if (is instanceof HasStreamInfo) { 27 | return ((HasStreamInfo) is).getInfo (); 28 | } 29 | try { 30 | return new AndroidWavHelper ().readMetadata (new AudioInputStream (is)); 31 | } catch (final IOException e) { 32 | throw new SoundTransformException (AudioFormatParserErrorCode.READ_ERROR, e); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/WavOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import java.io.DataOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | class WavOutputStream extends DataOutputStream { 8 | 9 | private static final int INTEGER_NUMBER_OF_BYTES = Integer.SIZE / Byte.SIZE; 10 | private static final int BYTE_MAX_VALUE = (1 << Byte.SIZE) - 1; 11 | 12 | public WavOutputStream (final OutputStream stream) { 13 | super (stream); 14 | } 15 | 16 | private byte [] intToByteArray (final int n) { 17 | final byte [] b = new byte [WavOutputStream.INTEGER_NUMBER_OF_BYTES]; 18 | for (int i = 0 ; i < b.length ; i++) { 19 | b [i] = (byte) (n >> i * Byte.SIZE); 20 | } 21 | return b; 22 | } 23 | 24 | private byte [] shortToByteArray (final int i) { 25 | return new byte [] { (byte) (i & WavOutputStream.BYTE_MAX_VALUE), (byte) (i >> Byte.SIZE & WavOutputStream.BYTE_MAX_VALUE) }; 26 | } 27 | 28 | public void writeInteger (final int i) throws IOException { 29 | this.write (this.intToByteArray (i)); 30 | } 31 | 32 | public void writeShortInt (final int i) throws IOException { 33 | this.write (this.shortToByteArray (i)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/WavReadableOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | 5 | class WavReadableOutputStream extends WavOutputStream { 6 | 7 | public WavReadableOutputStream (final ByteArrayOutputStream stream) { 8 | super (stream); 9 | } 10 | 11 | public byte [] getContent () { 12 | return ((ByteArrayOutputStream) this.out).toByteArray (); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/AudioFormatConverterAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.AudioFormatAccessor; 4 | import org.toilelibre.libe.soundtransform.model.inputstream.convert.ConverterLauncher; 5 | 6 | public abstract class AudioFormatConverterAccessor extends AudioFormatAccessor { 7 | 8 | protected ConverterLauncher provideConverterLauncher () { 9 | return new ProxyConverterLauncher (); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/Converter.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.InputStream; 5 | import java.util.Map.Entry; 6 | 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | 10 | interface Converter { 11 | Entry convert (InputStream input) throws SoundTransformException; 12 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/ConverterMapping.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | public enum ConverterMapping { 4 | OGG (new JorbisCleanConverter ()), MP3 (new MP3JLayerConverter ()); 5 | 6 | private final Converter converter; 7 | 8 | ConverterMapping (final Converter converter1) { 9 | this.converter = converter1; 10 | } 11 | 12 | public Converter getConverter () { 13 | return this.converter; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/JorbisReadException.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | public class JorbisReadException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -6967135552733918866L; 9 | 10 | public JorbisReadException (final String detailMessage, final Throwable throwable) { 11 | super (detailMessage, throwable); 12 | } 13 | 14 | public JorbisReadException (final String detailMessage) { 15 | super (detailMessage); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/ProxyConverterLauncher.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.InputStream; 5 | import java.util.Map.Entry; 6 | 7 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 8 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 10 | import org.toilelibre.libe.soundtransform.model.inputstream.convert.ConverterLauncher; 11 | import org.toilelibre.libe.soundtransform.model.logging.AbstractLogAware; 12 | 13 | @Processor 14 | class ProxyConverterLauncher extends AbstractLogAware implements ConverterLauncher { 15 | 16 | @Override 17 | public Entry convert (final Converter converter, final InputStream inputStream) throws SoundTransformException { 18 | return converter.convert (inputStream); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/converter/ResultEntry.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.util.Map.Entry; 5 | 6 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 7 | 8 | class ResultEntry implements Entry { 9 | 10 | private final StreamInfo streamInfo; 11 | private final ByteArrayOutputStream outputStream; 12 | 13 | public ResultEntry (final StreamInfo streamInfo1, final ByteArrayOutputStream outputStream1) { 14 | this.streamInfo = streamInfo1; 15 | this.outputStream = outputStream1; 16 | } 17 | 18 | @Override 19 | public StreamInfo getKey () { 20 | return this.streamInfo; 21 | } 22 | 23 | @Override 24 | public ByteArrayOutputStream getValue () { 25 | return this.outputStream; 26 | } 27 | 28 | @Override 29 | public ByteArrayOutputStream setValue (final ByteArrayOutputStream object) { 30 | throw new UnsupportedOperationException (); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/javax/JavaxAudioFormatAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.javax; 2 | 3 | import org.toilelibre.libe.soundtransform.ioc.AllAgnosticAccessorsAndBindings; 4 | import org.toilelibre.libe.soundtransform.model.inputstream.AudioFileHelper; 5 | import org.toilelibre.libe.soundtransform.model.inputstream.convert.ConvertProcessor; 6 | import org.toilelibre.libe.soundtransform.model.inputstream.format.AudioFormatParser; 7 | 8 | public abstract class JavaxAudioFormatAccessor extends AllAgnosticAccessorsAndBindings { 9 | 10 | @Override 11 | protected AudioFileHelper provideAudioFileHelper () { 12 | return new JavazoomAudioFileHelper (); 13 | } 14 | 15 | @Override 16 | protected AudioFormatParser provideAudioFormatParser () { 17 | return new WavAudioFormatParser (); 18 | } 19 | 20 | @Override 21 | protected ConvertProcessor provideConvertProcessor () { 22 | return new JavaxConvertProcessor (); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/converted/sound/transforms/GaussianEqualizerSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms; 2 | 3 | import org.apache.commons.math3.complex.Complex; 4 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SimpleFrequencySoundTransform; 6 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 7 | 8 | /** 9 | * 10 | * Equalizer which cuts the treble and the bass frequencies of a sound 11 | * 12 | */ 13 | public class GaussianEqualizerSoundTransform extends SimpleFrequencySoundTransform { 14 | 15 | private static final int DELTA_X = 3500; 16 | private static final int EXPONENT = 2; 17 | private static final int DIVISION = 1000; 18 | private static final int HALF = 2; 19 | 20 | /** 21 | * Default constructor 22 | */ 23 | public GaussianEqualizerSoundTransform () { 24 | super (); 25 | } 26 | 27 | private Complex function (final double x) { 28 | return new Complex (1 - Math.exp (-Math.pow (x - GaussianEqualizerSoundTransform.DELTA_X, GaussianEqualizerSoundTransform.EXPONENT) / GaussianEqualizerSoundTransform.DIVISION) / GaussianEqualizerSoundTransform.HALF); 29 | } 30 | 31 | @Override 32 | public Spectrum transformFrequencies (final Spectrum fs, final int offset, final int powOf2NearestLength, final int length) { 33 | final Complex [] newAmpl = new Complex [powOf2NearestLength]; 34 | for (double j = 0 ; j < length ; j++) { 35 | final double freq = j * fs.getSampleRate () / fs.getState ().length; 36 | newAmpl [(int) j] = fs.getState () [(int) j].multiply (this.function (freq)); 37 | } 38 | for (int j = length ; j < powOf2NearestLength ; j++) { 39 | newAmpl [j] = new Complex (0, 0); 40 | } 41 | return new Spectrum (newAmpl, new FormatInfo (fs.getSampleSize (), fs.getSampleRate ())); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/converted/sound/transforms/LevelSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.ComputeMagnitudeSoundTransform; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SoundTransform; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | 8 | public class LevelSoundTransform implements SoundTransform { 9 | 10 | private static final double NB_BYTE_VALUES = 1 << Byte.SIZE; 11 | private final int step; 12 | 13 | public LevelSoundTransform (final int step1) { 14 | this.step = step1; 15 | } 16 | 17 | @Override 18 | public Channel transform (final Channel input) throws SoundTransformException { 19 | final double [] magnitudes = new ComputeMagnitudeSoundTransform (this.step).transform (input); 20 | 21 | final long [] newdata = new long [input.getSamplesLength ()]; 22 | 23 | final double maxMagnitude = Math.pow (LevelSoundTransform.NB_BYTE_VALUES, input.getSampleSize ()) - 1; 24 | 25 | // now find the result, with scaling: 26 | for (int i = 0 ; i < input.getSamplesLength () ; i++) { 27 | final int currentMagnitudeIndex = (int) (i * 1.0 / this.step); 28 | final double rescaled = input.getSampleAt (i) / magnitudes [currentMagnitudeIndex] * maxMagnitude; 29 | newdata [i] = (long) Math.floor (rescaled); 30 | } 31 | 32 | // normalized result in newdata 33 | return new Channel (newdata, input.getFormatInfo (), input.getChannelNum ()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/converted/sound/transforms/LinearRegressionSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms; 2 | 3 | import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; 4 | import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SoundTransform; 7 | 8 | /** 9 | * Smoothes a sound graph. The effect is to remove the treble frequencies 10 | * without any time-to-frequency domain transform 11 | * 12 | */ 13 | public class LinearRegressionSoundTransform implements SoundTransform { 14 | 15 | private final int step; 16 | 17 | /** 18 | * Default constructor 19 | * 20 | * @param step1 21 | * iteration step value 22 | */ 23 | public LinearRegressionSoundTransform (final int step1) { 24 | this.step = step1; 25 | } 26 | 27 | @Override 28 | public Channel transform (final Channel input) { 29 | final SplineInterpolator reg = new SplineInterpolator (); 30 | final double [] x = new double [input.getSamplesLength () / this.step]; 31 | final double [] y = new double [input.getSamplesLength () / this.step]; 32 | for (int i = 0 ; i < input.getSamplesLength () ; i += this.step) { 33 | if (i / this.step < x.length) { 34 | x [i / this.step] = i; 35 | y [i / this.step] = input.getSampleAt (i); 36 | } 37 | } 38 | 39 | final PolynomialSplineFunction psf = reg.interpolate (x, y); 40 | 41 | final Channel outputSound = new Channel (new long [input.getSamplesLength ()], input.getFormatInfo (), input.getChannelNum ()); 42 | for (int i = 0 ; i < input.getSamplesLength () ; i++) { 43 | if (i < x [x.length - 1]) { 44 | outputSound.setSampleAt (i, (long) psf.value (i)); 45 | } else { 46 | outputSound.setSampleAt (i, input.getSampleAt (i)); 47 | } 48 | } 49 | 50 | return outputSound; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/converted/sound/transforms/PralongAndCarlileSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms; 2 | 3 | import org.apache.commons.math3.complex.Complex; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SimpleFrequencySoundTransform; 5 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 6 | 7 | public class PralongAndCarlileSoundTransform extends SimpleFrequencySoundTransform { 8 | 9 | private static final double [] RANGES = { 0, 10, 100, 125, 130, 150, 250, 500, 1000, 1237.384651, 1531.120775, 1894.585346, 2002.467159, 2344.330828, 2721.273584, 3001.403462, 3589.453635, 4001.342781, 4441.534834, 5004.212211, 5495.887031, 5997.423738, 6800.526258, 6946.931144, 10 | 7995.508928, 8414.866811, 9008.422743, 20000, 48000 }; 11 | private static final double [] AMPLIFICATION = { 0.08, 0.1, 0.81, 1, 1, 1, 1, 1, 0.994850557, 0.994850557, 0.994850557, 1.114513162, 1.235743262, 1.867671314, 2.822751493, 2.180544843, 1.442755787, 1.173563859, 1.37016005, 1.599690164, 1.37016005, 1.114513162, 0.648125625, 0.631609176, 12 | 0.276505667, 0.084335217, 0.084335217, 0, 0 }; 13 | private final EqualizerSoundTransform decoratedSoundTransform; 14 | 15 | public PralongAndCarlileSoundTransform () { 16 | this.decoratedSoundTransform = new EqualizerSoundTransform (PralongAndCarlileSoundTransform.RANGES, PralongAndCarlileSoundTransform.AMPLIFICATION); 17 | } 18 | 19 | @Override 20 | public Spectrum transformFrequencies (final Spectrum fs, final int offset, final int powOf2NearestLength, final int length) { 21 | return this.decoratedSoundTransform.transformFrequencies (fs, offset, powOf2NearestLength, length); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/fourier/FourierAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.fourier; 2 | 3 | import org.apache.commons.math3.complex.Complex; 4 | import org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.converter.AudioFormatConverterAccessor; 5 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.FourierTransformHelper; 6 | 7 | public abstract class FourierAccessor extends AudioFormatConverterAccessor { 8 | 9 | protected FourierTransformHelper provideFourierTransformHelper () { 10 | return new CommonsMath3FourierTransformHelper (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/frames/FrameProcessorAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.frames; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.fourier.FourierAccessor; 4 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.FrameProcessor; 5 | import org.toilelibre.libe.soundtransform.model.logging.AbstractLogAware; 6 | 7 | public abstract class FrameProcessorAccessor extends FourierAccessor { 8 | 9 | protected FrameProcessor> provideFrameProcessor () { 10 | return new ByteArrayFrameProcessor (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/AdjustFrequenciesToPianoProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.freqs.AdjustFrequenciesProcessor; 5 | import org.toilelibre.libe.soundtransform.model.freqs.PianoFrequency.PianoValues; 6 | 7 | @Processor 8 | final class AdjustFrequenciesToPianoProcessor implements AdjustFrequenciesProcessor { 9 | 10 | @Override 11 | public float [] adjust (final float [] freqs) { 12 | final float [] output = new float [freqs.length]; 13 | for (int i = 0 ; i < freqs.length ; i++) { 14 | output [i] = PianoValues.getNearestNote (freqs [i]).getFrequency (); 15 | } 16 | return output; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/FreqsAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.frames.FrameProcessorAccessor; 4 | import org.toilelibre.libe.soundtransform.model.freqs.AdjustFrequenciesProcessor; 5 | import org.toilelibre.libe.soundtransform.model.freqs.ChangeOctaveProcessor; 6 | import org.toilelibre.libe.soundtransform.model.freqs.CompressFrequenciesProcessor; 7 | import org.toilelibre.libe.soundtransform.model.freqs.FilterFrequenciesProcessor; 8 | import org.toilelibre.libe.soundtransform.model.freqs.ReplaceFrequenciesProcessor; 9 | import org.toilelibre.libe.soundtransform.model.freqs.SurroundInRangeProcessor; 10 | 11 | public abstract class FreqsAccessor extends FrameProcessorAccessor { 12 | 13 | protected AdjustFrequenciesProcessor provideAdjustFrequenciesProcessor () { 14 | return new AdjustFrequenciesToPianoProcessor (); 15 | } 16 | 17 | protected ChangeOctaveProcessor provideChangeOctaveProcessor () { 18 | return new SimpleChangeOctaveProcessor (); 19 | } 20 | 21 | protected CompressFrequenciesProcessor provideCompressFrequenciesProcessor () { 22 | return new SimpleCompressFrequenciesProcessor (); 23 | } 24 | 25 | protected FilterFrequenciesProcessor provideFilterFrequenciesProcessor () { 26 | return new SimpleFilterFrequenciesProcessor (); 27 | } 28 | 29 | protected ReplaceFrequenciesProcessor provideReplaceFrequenciesProcessor () { 30 | return new SimpleReplaceFrequenciesProcessor (); 31 | } 32 | 33 | protected SurroundInRangeProcessor provideSurroundInRangeFrequenciesProcessor () { 34 | return new SimpleSurroundInOctaveProcessor (); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/SimpleChangeOctaveProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.freqs.ChangeOctaveProcessor; 5 | 6 | @Processor 7 | final class SimpleChangeOctaveProcessor implements ChangeOctaveProcessor { 8 | 9 | @Override 10 | public float [] multFreqs (final float [] freqs, final float factor) { 11 | final float [] output = new float [freqs.length]; 12 | for (int i = 0 ; i < freqs.length ; i++) { 13 | output [i] = freqs [i] * factor; 14 | } 15 | return output; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/SimpleCompressFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.freqs.CompressFrequenciesProcessor; 5 | 6 | @Processor 7 | final class SimpleCompressFrequenciesProcessor implements CompressFrequenciesProcessor { 8 | 9 | /* 10 | * (non-Javadoc) 11 | * 12 | * @see org.toilelibre.libe.soundtransform.infrastructure.service.freqs. 13 | * CompressFrequenciesProcessor#compress(float[], float) 14 | */ 15 | @Override 16 | public float [] compress (final float [] array, final float factor) { 17 | final float factorInv = 1.0f / factor; 18 | final float [] result = new float [(int) Math.ceil (array.length * factorInv)]; 19 | float writeWhileLessThan1 = 1; 20 | int resultIndex = 0; 21 | for (final float element : array) { 22 | writeWhileLessThan1--; 23 | while (writeWhileLessThan1 < 1) { 24 | result [resultIndex++] = element; 25 | writeWhileLessThan1 += factor; 26 | } 27 | } 28 | return result; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/SimpleFilterFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | import org.toilelibre.libe.soundtransform.model.freqs.FilterFrequenciesProcessor; 6 | 7 | @Processor 8 | final class SimpleFilterFrequenciesProcessor implements FilterFrequenciesProcessor { 9 | 10 | @Override 11 | public float [] filter (final float [] freqs, final float low, final float high) throws SoundTransformException { 12 | if (low >= high) { 13 | throw new SoundTransformException (FilterFrequenciesProcessorErrorCode.INVALID_RANGE, new IndexOutOfBoundsException (), low, high); 14 | } 15 | final float [] result = new float [freqs.length]; 16 | for (int i = 0 ; i < result.length ; i++) { 17 | if (freqs [i] < low || freqs [i] > high) { 18 | result [i] = freqs [i]; 19 | } 20 | } 21 | return result; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/SimpleReplaceFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.freqs.ReplaceFrequenciesProcessor; 5 | 6 | @Processor 7 | final class SimpleReplaceFrequenciesProcessor implements ReplaceFrequenciesProcessor { 8 | 9 | @Override 10 | public float [] insertPart (final float [] freqs, final float [] subFreqs, final int start) { 11 | final float [] result = new float [Math.max (start, freqs.length) + subFreqs.length]; 12 | System.arraycopy (freqs, 0, result, 0, Math.min (start, freqs.length)); 13 | System.arraycopy (subFreqs, 0, result, start, subFreqs.length); 14 | if (freqs.length - start > 0) { 15 | System.arraycopy (freqs, start, result, start + subFreqs.length, freqs.length - start); 16 | } 17 | return result; 18 | } 19 | 20 | @Override 21 | public float [] replacePart (final float [] freqs, final float [] subFreqs, final int start) { 22 | final float [] result = new float [Math.max (freqs.length, start + subFreqs.length)]; 23 | System.arraycopy (freqs, 0, result, 0, freqs.length); 24 | System.arraycopy (subFreqs, 0, result, start, subFreqs.length); 25 | return result; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/freqs/SimpleSurroundInOctaveProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | import org.toilelibre.libe.soundtransform.model.freqs.SurroundInRangeProcessor; 6 | 7 | @Processor 8 | final class SimpleSurroundInOctaveProcessor implements SurroundInRangeProcessor { 9 | 10 | private static final float OCTAVE_HALF = 1.5f; 11 | private static final float TWO = 2f; 12 | 13 | @Override 14 | public float [] surroundFreqsInRange (final float [] freqs, final float low, final float high) throws SoundTransformException { 15 | if (low >= high) { 16 | throw new SoundTransformException (SurroundInRangeProcessorErrorCode.INVALID_RANGE, new IndexOutOfBoundsException (), low, high); 17 | } 18 | final float [] output = new float [freqs.length]; 19 | for (int i = 0 ; i < freqs.length ; i++) { 20 | output [i] = this.surroundFreqInRange (freqs [i], low, high); 21 | } 22 | return output; 23 | } 24 | 25 | private float surroundFreqInRange (final float inputValue, final float low, final float high) { 26 | float result = inputValue; 27 | if (result == 0) { 28 | return 0; 29 | } 30 | while (result < low) { 31 | result *= SimpleSurroundInOctaveProcessor.TWO; 32 | } 33 | while (result > high) { 34 | result /= SimpleSurroundInOctaveProcessor.TWO; 35 | } 36 | 37 | while (result < low && result * SimpleSurroundInOctaveProcessor.TWO > high) { 38 | result *= SimpleSurroundInOctaveProcessor.OCTAVE_HALF; 39 | } 40 | return result; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/pack/GsonPackConfigParser.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.pack; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 7 | import org.toilelibre.libe.soundtransform.model.library.pack.PackConfigParser; 8 | 9 | import com.google.gson.Gson; 10 | 11 | @Processor 12 | final class GsonPackConfigParser implements PackConfigParser { 13 | 14 | @Override 15 | public Map>> parse (final String input) { 16 | final Gson gson = new Gson (); 17 | return gson.>>> fromJson (input, Map.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/pack/PackAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.pack; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.freqs.FreqsAccessor; 4 | import org.toilelibre.libe.soundtransform.model.library.pack.PackConfigParser; 5 | import org.toilelibre.libe.soundtransform.model.library.pack.PackToStringHelper; 6 | 7 | public abstract class PackAccessor extends FreqsAccessor { 8 | 9 | protected PackToStringHelper providePack2StringHelper () { 10 | return new GsonPackToStringHelper (); 11 | } 12 | 13 | protected PackConfigParser providePackConfigParser () { 14 | return new GsonPackConfigParser (); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/play/android/AndroidPlayAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.play.android; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android.AndroidAudioFormatAccessor; 4 | import org.toilelibre.libe.soundtransform.model.play.PlayObjectProcessor; 5 | 6 | public abstract class AndroidPlayAccessor extends AndroidAudioFormatAccessor { 7 | 8 | @Override 9 | protected PlayObjectProcessor providePlaySoundProcessor () { 10 | return new AndroidPlayObjectProcessor (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/play/javax/JavaxPlayAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.play.javax; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.javax.JavaxAudioFormatAccessor; 4 | import org.toilelibre.libe.soundtransform.model.play.PlayObjectProcessor; 5 | 6 | public abstract class JavaxPlayAccessor extends JavaxAudioFormatAccessor { 7 | 8 | @Override 9 | protected PlayObjectProcessor providePlaySoundProcessor () { 10 | return new LineListenerPlayObjectProcessor (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/android/AndroidRecordAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.android; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.play.android.AndroidPlayAccessor; 4 | import org.toilelibre.libe.soundtransform.model.record.RecordSoundProcessor; 5 | 6 | public abstract class AndroidRecordAccessor extends AndroidPlayAccessor { 7 | 8 | @Override 9 | protected RecordSoundProcessor provideRecordSoundProcessor () { 10 | return new AndroidRecordSoundProcessor (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/android/TestAudioRecordInitializer.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.android; 2 | 3 | import android.media.AudioRecord; 4 | 5 | public class TestAudioRecordInitializer { 6 | 7 | static AudioRecord audioRecord; 8 | static Integer minBufferSize; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/exporter/ByteArrayOutputStreamExporter.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.exporter; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 6 | import org.toilelibre.libe.soundtransform.model.record.exporter.BytesExporterFromThread; 7 | import org.toilelibre.libe.soundtransform.model.record.exporter.OutputAsByteArrayOutputStream; 8 | 9 | @Processor 10 | class ByteArrayOutputStreamExporter implements BytesExporterFromThread, OutputAsByteArrayOutputStream { 11 | 12 | private ByteArrayOutputStream outputStream; 13 | private int bufferSize; 14 | 15 | ByteArrayOutputStreamExporter () { 16 | } 17 | 18 | @Override 19 | public void init (final int bufferSize1) { 20 | this.bufferSize = bufferSize1; 21 | this.outputStream = new ByteArrayOutputStream (bufferSize); 22 | } 23 | 24 | @Override 25 | public int getReportedBufferSize () { 26 | return this.bufferSize; 27 | } 28 | 29 | 30 | @Override 31 | public void export (final byte [] byteArray, final int readSize) { 32 | this.outputStream.write (byteArray, 0, readSize); 33 | } 34 | 35 | @Override 36 | public ByteArrayOutputStream getOutput () { 37 | return this.outputStream; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/exporter/ByteBufferExporter.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.exporter; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 6 | import org.toilelibre.libe.soundtransform.model.record.exporter.BytesExporterFromThread; 7 | import org.toilelibre.libe.soundtransform.model.record.exporter.OutputAsByteBuffer; 8 | 9 | @Processor 10 | class ByteBufferExporter implements BytesExporterFromThread, OutputAsByteBuffer { 11 | 12 | private ByteBuffer buffer; 13 | private int bufferSize; 14 | 15 | ByteBufferExporter () { 16 | } 17 | 18 | @Override 19 | public void init (final int bufferSize1) { 20 | this.bufferSize = bufferSize1; 21 | this.buffer = ByteBuffer.allocate (bufferSize1); 22 | } 23 | 24 | @Override 25 | public int getReportedBufferSize () { 26 | return this.bufferSize; 27 | } 28 | 29 | @Override 30 | public void export (final byte [] byteArray, final int readSize) { 31 | this.buffer.rewind (); 32 | this.buffer.put (byteArray, 0, readSize); 33 | synchronized (this.buffer) { 34 | this.buffer.notifyAll (); 35 | } 36 | } 37 | 38 | @Override 39 | public ByteBuffer getOutput () { 40 | return this.buffer; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/exporter/BytesExportAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.exporter; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.pack.PackAccessor; 4 | import org.toilelibre.libe.soundtransform.model.record.exporter.OutputAsByteArrayOutputStream; 5 | import org.toilelibre.libe.soundtransform.model.record.exporter.OutputAsByteBuffer; 6 | 7 | public abstract class BytesExportAccessor extends PackAccessor { 8 | 9 | protected OutputAsByteArrayOutputStream providerByteArrayOutputStreamExporter () { 10 | return new ByteArrayOutputStreamExporter (); 11 | } 12 | 13 | protected OutputAsByteBuffer providerByteBufferOutputStreamExporter () { 14 | return new ByteBufferExporter (); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/javax/JavaxRecordAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.javax; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.play.javax.JavaxPlayAccessor; 4 | import org.toilelibre.libe.soundtransform.model.record.RecordSoundProcessor; 5 | 6 | public abstract class JavaxRecordAccessor extends JavaxPlayAccessor { 7 | 8 | @Override 9 | protected RecordSoundProcessor provideRecordSoundProcessor () { 10 | return new TargetDataLineRecordSoundProcessor (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/record/javax/TargetDataLineReaderThread.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.record.javax; 2 | 3 | import javax.sound.sampled.TargetDataLine; 4 | 5 | import org.toilelibre.libe.soundtransform.model.record.exporter.BytesExporterFromThread; 6 | 7 | final class TargetDataLineReaderThread extends Thread { 8 | /** 9 | * 10 | */ 11 | private final TargetDataLine dataLine; 12 | private boolean isRecording; 13 | private final BytesExporterFromThread exporter; 14 | private static final int FIVE = 5; 15 | 16 | /** 17 | * @param dataLine1 18 | */ 19 | TargetDataLineReaderThread (final TargetDataLine dataLine1, final BytesExporterFromThread exporter1) { 20 | this.dataLine = dataLine1; 21 | this.exporter = exporter1; 22 | this.setName (this.getClass ().getSimpleName ()); 23 | } 24 | 25 | public void stopRecording () { 26 | this.isRecording = false; 27 | } 28 | 29 | @Override 30 | public void run () { 31 | this.isRecording = true; 32 | final byte [] data = new byte [this.dataLine.getBufferSize () / TargetDataLineReaderThread.FIVE]; 33 | while (this.isRecording) { 34 | // Read the next chunk of data from the TargetDataLine. 35 | final int numBytesRead = this.dataLine.read (data, 0, data.length); 36 | // Save this chunk of data. 37 | this.exporter.export (data, numBytesRead); 38 | } 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/CallHPSFrequencyHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 7 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.HarmonicProductSpectrumSoundTransform; 9 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.PeakFindSoundTransform; 10 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 11 | import org.toilelibre.libe.soundtransform.model.library.pack.note.FrequencyHelper; 12 | 13 | @Processor 14 | final class CallHPSFrequencyHelper implements FrequencyHelper { 15 | 16 | @Override 17 | public float findFrequency (final Sound sound) throws SoundTransformException { 18 | final PeakFindSoundTransform peak = new HarmonicProductSpectrumSoundTransform (true, true); 19 | float value = 0; 20 | float volume = 0; 21 | for (final Channel channel : sound.getChannels ()) { 22 | final float [] freqs = peak.transform (channel); 23 | if (volume < peak.getDetectedNoteVolume ()) { 24 | value = freqs [0]; 25 | volume = peak.getDetectedNoteVolume (); 26 | } 27 | } 28 | 29 | return value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/SoundToNoteAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.record.exporter.BytesExportAccessor; 4 | import org.toilelibre.libe.soundtransform.model.library.pack.note.ADSRHelper; 5 | import org.toilelibre.libe.soundtransform.model.library.pack.note.FrequencyHelper; 6 | 7 | public abstract class SoundToNoteAccessor extends BytesExportAccessor { 8 | 9 | protected FrequencyHelper provideFrequencyHelper () { 10 | return new CallHPSFrequencyHelper (); 11 | } 12 | 13 | protected ADSRHelper provideAdsrHelper () { 14 | return new MagnitudeADSRHelper (); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/android/AndroidContextLoaderAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.android; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.record.android.AndroidRecordAccessor; 4 | import org.toilelibre.libe.soundtransform.model.library.pack.ContextLoader; 5 | 6 | public abstract class AndroidContextLoaderAccessor extends AndroidRecordAccessor { 7 | 8 | @Override 9 | protected ContextLoader provideContextLoader () { 10 | return new AndroidContextLoader (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/javax/ErrorContextLoader.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.javax; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 6 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.library.pack.ContextLoader; 9 | 10 | @Processor 11 | final class ErrorContextLoader implements ContextLoader { 12 | 13 | private enum ErrorContextReaderErrorCode implements ErrorCode { 14 | STUB_IMPLEMENTATION ("Stub implementation of the context reader with javax. This json pack cannot be imported in the javax impl."); 15 | 16 | private final String messageFormat; 17 | 18 | ErrorContextReaderErrorCode (final String mF) { 19 | this.messageFormat = mF; 20 | } 21 | 22 | @Override 23 | public String getMessageFormat () { 24 | return this.messageFormat; 25 | } 26 | } 27 | 28 | @Override 29 | public InputStream read (final Object context, final int id) throws SoundTransformException { 30 | throw new SoundTransformException (ErrorContextReaderErrorCode.STUB_IMPLEMENTATION, new UnsupportedOperationException ()); 31 | } 32 | 33 | @Override 34 | public InputStream read (final Object context, final Class rClass, final String idName) throws SoundTransformException { 35 | return this.read (context, 0); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/javax/JavaxContextLoaderAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.javax; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.record.javax.JavaxRecordAccessor; 4 | import org.toilelibre.libe.soundtransform.model.library.pack.ContextLoader; 5 | 6 | public abstract class JavaxContextLoaderAccessor extends JavaxRecordAccessor { 7 | 8 | @Override 9 | protected ContextLoader provideContextLoader () { 10 | return new ErrorContextLoader (); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2string/GraphSoundToStringHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2string; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.SoundToStringHelper; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.ToStringSoundTransform; 7 | 8 | @Processor 9 | final class GraphSoundToStringHelper implements SoundToStringHelper { 10 | 11 | private static final int ARBITRARY_LENGTH = 8000; 12 | private static final int ARBITRARY_HEIGHT = 20; 13 | 14 | /* 15 | * (non-Javadoc) 16 | * 17 | * @see 18 | * org.toilelibre.libe.soundtransform.infrastructure.service.sound2string 19 | * .Sound2StringHelper 20 | * #process(org.toilelibre.libe.soundtransform.model.converted.sound.Sound) 21 | */ 22 | @Override 23 | public String process (final Channel input) { 24 | return new ToStringSoundTransform (GraphSoundToStringHelper.ARBITRARY_LENGTH, GraphSoundToStringHelper.ARBITRARY_HEIGHT).toString (input); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2string/SoundToStringAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2string; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.SoundToNoteAccessor; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.SoundToStringHelper; 5 | 6 | public abstract class SoundToStringAccessor extends SoundToNoteAccessor { 7 | 8 | protected SoundToStringHelper provideSound2StringHelper () { 9 | return new GraphSoundToStringHelper (); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/spectrum/NaiveSpectrumToCepstrumHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.spectrum; 2 | 3 | import org.apache.commons.math3.complex.Complex; 4 | import org.apache.commons.math3.transform.DftNormalization; 5 | import org.apache.commons.math3.transform.FastFourierTransformer; 6 | import org.apache.commons.math3.transform.TransformType; 7 | import org.toilelibre.libe.soundtransform.infrastructure.service.Processor; 8 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 9 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.SpectrumToCepstrumHelper; 10 | 11 | @Processor 12 | final class NaiveSpectrumToCepstrumHelper implements SpectrumToCepstrumHelper { 13 | 14 | private static final double A_CONSTANT_TO_REDUCE_OCTAVE_ERRORS = 10.0; 15 | 16 | @Override 17 | public Spectrum spectrumToCepstrum (final Spectrum spectrum) { 18 | final double [] logSpectrumReals = new double [spectrum.getState ().length]; 19 | 20 | for (int i = 0 ; i < logSpectrumReals.length ; i++) { 21 | logSpectrumReals [i] = Math.log (1 + NaiveSpectrumToCepstrumHelper.A_CONSTANT_TO_REDUCE_OCTAVE_ERRORS * spectrum.getState () [i].abs ()); 22 | } 23 | final FastFourierTransformer fastFourierTransformer = new FastFourierTransformer (DftNormalization.STANDARD); 24 | 25 | return new Spectrum (fastFourierTransformer.transform (logSpectrumReals, TransformType.INVERSE), spectrum.getFormatInfo ()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/infrastructure/service/spectrum/SpectrumAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.spectrum; 2 | 3 | import org.apache.commons.math3.complex.Complex; 4 | import org.toilelibre.libe.soundtransform.infrastructure.service.sound2string.SoundToStringAccessor; 5 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.SpectrumHelper; 6 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.SpectrumToCepstrumHelper; 7 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.SpectrumToStringHelper; 8 | 9 | public abstract class SpectrumAccessor extends SoundToStringAccessor { 10 | 11 | protected SpectrumToStringHelper provideSpectrumToStringHelper () { 12 | return new GraphSpectrumToStringHelper (this.provideSpectrumHelper ()); 13 | } 14 | 15 | protected SpectrumHelper provideSpectrumHelper () { 16 | return new HPSSpectrumHelper (); 17 | } 18 | 19 | protected SpectrumToCepstrumHelper provideSpectrum2CepstrumHelper () { 20 | return new NaiveSpectrumToCepstrumHelper (); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/AllAgnosticAccessorsAndBindings.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | public abstract class AllAgnosticAccessorsAndBindings extends ImplAgnosticRootModule { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/AllServicesAccessors.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import org.toilelibre.libe.soundtransform.model.record.RecordAccessor; 4 | 5 | public abstract class AllServicesAccessors extends RecordAccessor { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/ApplicationInjector.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import se.jbee.inject.Dependency; 4 | import se.jbee.inject.Injector; 5 | import se.jbee.inject.bootstrap.Bootstrap; 6 | 7 | public class ApplicationInjector { 8 | 9 | static final String RUNTIME_SYSTEM_PROPERTY = "java.vm.vendor"; 10 | 11 | static Injector injector = Bootstrap.injector (ImplChooser.getCorrectImplModule (System.getProperty (ApplicationInjector.RUNTIME_SYSTEM_PROPERTY))); 12 | 13 | private ApplicationInjector () { 14 | 15 | } 16 | 17 | public static class $ { 18 | 19 | private $ () { 20 | 21 | } 22 | 23 | public static T select (final Class type) { 24 | return ApplicationInjector.getBean (type); 25 | } 26 | 27 | } 28 | 29 | private static T getBean (final Class type) { 30 | return ApplicationInjector.injector.resolve (Dependency. dependency (type)); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/ImplAgnosticFinalAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.spectrum.SpectrumAccessor; 4 | 5 | abstract class ImplAgnosticFinalAccessor extends SpectrumAccessor { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/ImplChooser.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.toilelibre.libe.soundtransform.ioc.android.AndroidRootModule; 6 | import org.toilelibre.libe.soundtransform.ioc.javax.JavaXRootModule; 7 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 8 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformRuntimeException; 9 | 10 | enum ImplChooser { 11 | 12 | ANDROID (new String [] { "The Android Project" }, AndroidRootModule.class), JAVA (new String [] { "Oracle Corporation", "Sun Microsystems Inc.", "Azul Systems, Inc." }, JavaXRootModule.class); 13 | 14 | public enum ImplChooserErrorCode implements ErrorCode { 15 | INVALID_RUNTIME ("Invalid Java Runtime : %1s"); 16 | 17 | private final String messageFormat; 18 | 19 | ImplChooserErrorCode (final String mF) { 20 | this.messageFormat = mF; 21 | } 22 | 23 | @Override 24 | public String getMessageFormat () { 25 | return this.messageFormat; 26 | } 27 | } 28 | 29 | private final Class moduleClass; 30 | 31 | private final String [] acceptValues; 32 | 33 | ImplChooser (final String [] acceptValues1, final Class moduleClass1) { 34 | this.acceptValues = acceptValues1; 35 | this.moduleClass = moduleClass1; 36 | } 37 | 38 | @SuppressWarnings ("unchecked") 39 | static Class getCorrectImplModule (final String acceptValue1) { 40 | for (final ImplChooser runtime : ImplChooser.values ()) { 41 | if (Arrays.asList (runtime.acceptValues).contains (acceptValue1)) { 42 | return (Class) runtime.moduleClass; 43 | } 44 | } 45 | throw new SoundTransformRuntimeException (ImplChooserErrorCode.INVALID_RUNTIME, new IllegalArgumentException (), acceptValue1); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/RootModuleWithoutAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import se.jbee.inject.bind.BinderModule; 7 | 8 | public abstract class RootModuleWithoutAccessor extends BinderModule { 9 | 10 | protected Map, Class> usedImpls = new HashMap, Class> (); 11 | 12 | public RootModuleWithoutAccessor () { 13 | if (!this.getClass ().getPackage ().getName ().startsWith (RootModuleWithoutAccessor.class.getPackage ().getName ())) { 14 | throw new se.jbee.inject.DIRuntimeException ("Not allowed to override this lib accessors"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/android/AndroidFinalAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc.android; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.android.AndroidContextLoaderAccessor; 4 | 5 | abstract class AndroidFinalAccessor extends AndroidContextLoaderAccessor { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/android/AndroidRootModule.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc.android; 2 | 3 | public final class AndroidRootModule extends AndroidFinalAccessor { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/javax/JavaXRootModule.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc.javax; 2 | 3 | public final class JavaXRootModule extends JavaxFinalAccessor { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/ioc/javax/JavaxFinalAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc.javax; 2 | 3 | import org.toilelibre.libe.soundtransform.infrastructure.service.sound2note.javax.JavaxContextLoaderAccessor; 4 | 5 | abstract class JavaxFinalAccessor extends JavaxContextLoaderAccessor { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/Service.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.SOURCE) 7 | @Target(ElementType.TYPE) 8 | public @interface Service { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/FormatInfo.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted; 2 | 3 | import java.io.Serializable; 4 | import java.util.Locale; 5 | 6 | public class FormatInfo implements Serializable { 7 | 8 | private static final long serialVersionUID = 2807016563144431421L; 9 | 10 | private final int sampleSize; 11 | 12 | private final float sampleRate; 13 | 14 | public FormatInfo (final int sampleSize, final float sampleRate) { 15 | super (); 16 | this.sampleSize = sampleSize; 17 | this.sampleRate = sampleRate; 18 | } 19 | 20 | public float getSampleRate () { 21 | return this.sampleRate; 22 | } 23 | 24 | public int getSampleSize () { 25 | return this.sampleSize; 26 | } 27 | 28 | public boolean sameFormatAs (final FormatInfo fi) { 29 | return this.sampleRate == fi.sampleRate && this.sampleSize == fi.sampleSize; 30 | } 31 | 32 | @Override 33 | public String toString () { 34 | return String.format (Locale.ENGLISH, "%6.1f Hz, %1d bit", this.getSampleRate (), this.getSampleSize () * Byte.SIZE); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/CallTransformService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SoundTransform; 5 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.logging.EventCode; 8 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 9 | import org.toilelibre.libe.soundtransform.model.logging.LogEvent.LogLevel; 10 | 11 | @Service 12 | public interface CallTransformService extends LogAware { 13 | 14 | public enum CallTransformServiceErrorCode implements ErrorCode { 15 | 16 | NOTHING_IN_INPUT ("Nothing in input of the service"); 17 | 18 | private final String messageFormat; 19 | 20 | CallTransformServiceErrorCode (final String mF) { 21 | this.messageFormat = mF; 22 | } 23 | 24 | @Override 25 | public String getMessageFormat () { 26 | return this.messageFormat; 27 | } 28 | } 29 | 30 | public enum CallTransformServiceEventCode implements EventCode { 31 | 32 | TRANSFORM_STARTING (LogLevel.INFO, "Transform %3s, channel %4d/%5d"), TRANSFORMS_DONE (LogLevel.INFO, "Transforms done"); 33 | 34 | private final String messageFormat; 35 | private final LogLevel logLevel; 36 | 37 | CallTransformServiceEventCode (final LogLevel ll, final String mF) { 38 | this.messageFormat = mF; 39 | this.logLevel = ll; 40 | } 41 | 42 | @Override 43 | public LogLevel getLevel () { 44 | return this.logLevel; 45 | } 46 | 47 | @Override 48 | public String getMessageFormat () { 49 | return this.messageFormat; 50 | } 51 | } 52 | 53 | V [] apply (U [] input, SoundTransform transform) throws SoundTransformException; 54 | 55 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/DefaultSoundPitchAndTempoService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | @Service 7 | final class DefaultSoundPitchAndTempoService implements SoundPitchAndTempoService { 8 | 9 | private final SoundPitchAndTempoHelper helper; 10 | 11 | public DefaultSoundPitchAndTempoService (final SoundPitchAndTempoHelper helper1) { 12 | this.helper = helper1; 13 | } 14 | 15 | /* 16 | * (non-Javadoc) 17 | * 18 | * @see org.toilelibre.libe.soundtransform.model.converted.sound. 19 | * SoundPitchAndTempoService 20 | * #callTransform(org.toilelibre.libe.soundtransform 21 | * .model.converted.sound.Sound, float, float) 22 | */ 23 | @Override 24 | public Channel callTransform (final Channel sound, final float percent, final float lengthInSeconds) throws SoundTransformException { 25 | return this.helper.pitchAndSetLength (sound, percent, lengthInSeconds); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/DefaultSoundToStringService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | 5 | @Service 6 | final class DefaultSoundToStringService implements SoundToStringService { 7 | 8 | private final SoundToStringHelper helper; 9 | 10 | public DefaultSoundToStringService (final SoundToStringHelper helper1) { 11 | this.helper = helper1; 12 | } 13 | 14 | /* 15 | * (non-Javadoc) 16 | * 17 | * @see 18 | * org.toilelibre.libe.soundtransform.model.converted.sound.Sound2StringService 19 | * #convert(org.toilelibre.libe.soundtransform.model.converted.sound.Sound) 20 | */ 21 | @Override 22 | public String convert (final Channel input) { 23 | return this.helper.process (input); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/ModifySoundService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 5 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | 8 | @Service 9 | public interface ModifySoundService { 10 | 11 | enum ModifySoundServiceErrorCode implements ErrorCode { 12 | DIFFERENT_NUMBER_OF_CHANNELS ("Could not append two sounds : Different number of channels (%1d and %2d)"); 13 | 14 | private final String messageFormat; 15 | 16 | ModifySoundServiceErrorCode (final String mF) { 17 | this.messageFormat = mF; 18 | } 19 | 20 | @Override 21 | public String getMessageFormat () { 22 | return this.messageFormat; 23 | } 24 | 25 | } 26 | 27 | Sound append (Sound sounds1, Sound sounds2) throws SoundTransformException; 28 | 29 | Sound changeFormat (Sound input, FormatInfo formatInfo); 30 | 31 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SegmentedSound.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import java.util.List; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 6 | 7 | public class SegmentedSound extends Sound { 8 | 9 | private static final long serialVersionUID = -6795034869791734402L; 10 | 11 | public SegmentedSound (final FormatInfo formatInfo, final List sounds) { 12 | super (new Channel [] { new SegmentedChannel (formatInfo, sounds) }); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/Sound.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 6 | 7 | public class Sound implements Serializable { 8 | 9 | private static final long serialVersionUID = 8150171679999317728L; 10 | 11 | private final Channel [] channels; 12 | 13 | public Sound (final Channel [] channels1) { 14 | this.channels = channels1 == null ? new Channel [0] : channels1.clone (); 15 | } 16 | 17 | public Channel [] getChannels () { 18 | return this.channels.clone (); 19 | } 20 | 21 | public int getNumberOfChannels () { 22 | return this.channels.length; 23 | } 24 | 25 | public int getSamplesLength () { 26 | return this.channels.length == 0 ? 0 : this.channels [0].getSamplesLength (); 27 | } 28 | 29 | public FormatInfo getFormatInfo () { 30 | return this.channels.length == 0 ? null : this.channels [0].getFormatInfo (); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.ioc.RootModuleWithoutAccessor; 4 | 5 | public abstract class SoundAccessor extends RootModuleWithoutAccessor { 6 | 7 | public SoundAccessor () { 8 | this.usedImpls.put (SoundPitchAndTempoService.class, DefaultSoundPitchAndTempoService.class); 9 | this.usedImpls.put (ModifySoundService.class, DefaultModifySoundService.class); 10 | this.usedImpls.put (SoundToStringService.class, DefaultSoundToStringService.class); 11 | this.usedImpls.put (CallTransformService.class, DefaultCallTransformService.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundAppender.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | import org.toilelibre.libe.soundtransform.model.library.pack.note.Note; 5 | 6 | public interface SoundAppender { 7 | 8 | void append (Channel origin, int usedarraylength, Channel... otherSounds); 9 | 10 | int append (Channel origin, int usedarraylength, Channel otherSound); 11 | 12 | Channel append (Channel sound, Channel sound2); 13 | 14 | void appendNote (Channel sound, Note note, double lastFreq, int indexInSound, int channelNum, float lengthInSeconds) throws SoundTransformException; 15 | 16 | Channel changeNbBytesPerSample (Channel sound, int newNbBytesPerSample); 17 | 18 | Channel downsampleWithRatio (Channel sound, float ratio); 19 | 20 | Channel resizeToSampleRate (Channel sound, float newSampleRate); 21 | 22 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundPitchAndTempoHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public interface SoundPitchAndTempoHelper { 6 | 7 | Channel pitchAndSetLength (Channel sound, float percent, float lengthInSeconds) throws SoundTransformException; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundPitchAndTempoService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | @Service 7 | public interface SoundPitchAndTempoService { 8 | 9 | Channel callTransform (Channel sound, float percent, float lengthInSeconds) throws SoundTransformException; 10 | 11 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundToStringHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | public interface SoundToStringHelper { 4 | 5 | String process (Channel input); 6 | 7 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/SoundToStringService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | 5 | @Service 6 | interface SoundToStringService { 7 | 8 | String convert (Channel input); 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/AbstractFrequencySoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 6 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.FourierTransformHelper; 7 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 8 | import org.toilelibre.libe.soundtransform.model.logging.AbstractLogAware; 9 | 10 | public abstract class AbstractFrequencySoundTransform extends AbstractLogAware> implements SoundTransform { 11 | 12 | private static final double LOG_2 = Math.log (2); 13 | private static final int TWO = 2; 14 | private final FourierTransformHelper fourierTransformHelper; 15 | 16 | public AbstractFrequencySoundTransform (final FourierTransformHelper helper1) { 17 | this.fourierTransformHelper = helper1; 18 | } 19 | 20 | public abstract int getOffsetFromASimpleLoop (int i, double step); 21 | 22 | public abstract double getStep (double defaultValue); 23 | 24 | public abstract boolean isReverseNecessary (); 25 | 26 | public abstract boolean rawSpectrumPrefered (); 27 | 28 | public abstract AbstractWindowSoundTransform getWindowTransform (); 29 | 30 | public int getWindowLength (final double freqmax) { 31 | return (int) Math.pow (AbstractFrequencySoundTransform.TWO, Math.ceil (Math.log (freqmax) / AbstractFrequencySoundTransform.LOG_2)); 32 | } 33 | 34 | public abstract Channel initSound (Channel input); 35 | 36 | @Override 37 | public final Channel transform (final Channel sound) { 38 | return this.fourierTransformHelper.transform (this, sound); 39 | } 40 | 41 | public abstract Spectrum transformFrequencies (Spectrum fs, int offset, int powOf2NearestLength, int length, float soundLevelInDB); 42 | 43 | public abstract void transformFrequencies (double [][] spectrumAsDoubles, final float sampleRate, int offset, int powOf2NearestLength, int length, float soundLevelInDB); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/AbstractWindowSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | 5 | public abstract class AbstractWindowSoundTransform implements SoundTransform { 6 | 7 | @Override 8 | /** 9 | * @param progress is equal to iteration / sound.getSampleslength () - 1 10 | */ 11 | public Double transform (final Double progress) { 12 | 13 | return this.applyFunction (progress); 14 | } 15 | 16 | public Channel transformWholeChannel (final Channel sound) { 17 | 18 | final long [] newdata = new long [sound.getSamplesLength ()]; 19 | 20 | // now find the result, with scaling: 21 | for (int i = 0 ; i < sound.getSamplesLength () ; i++) { 22 | final double rescaled = sound.getSampleAt (i) * this.applyFunction (i * 1.0 / (sound.getSamplesLength () - 1)); 23 | newdata [i] = (long) rescaled; 24 | } 25 | 26 | // normalized result in newdata 27 | return new Channel (newdata, sound.getFormatInfo (), sound.getChannelNum ()); 28 | } 29 | 30 | protected abstract double applyFunction (double progress); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/BlackmanHarrisWindowSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | public final class BlackmanHarrisWindowSoundTransform extends AbstractWindowSoundTransform { 4 | 5 | private static final double COEFF1 = 0.35875; 6 | private static final double COEFF2 = 0.48829; 7 | private static final double COEFF3 = 0.14128; 8 | private static final double COEFF4 = 0.01168; 9 | private static final double TWO = 2; 10 | private static final double FOUR = 4; 11 | private static final double SIX = 6; 12 | 13 | @Override 14 | protected double applyFunction (final double progress) { 15 | return BlackmanHarrisWindowSoundTransform.COEFF1 - BlackmanHarrisWindowSoundTransform.COEFF2 * Math.cos (BlackmanHarrisWindowSoundTransform.TWO * Math.PI * progress) + BlackmanHarrisWindowSoundTransform.COEFF3 * Math.cos (BlackmanHarrisWindowSoundTransform.FOUR * Math.PI * progress) 16 | - BlackmanHarrisWindowSoundTransform.COEFF4 * Math.cos (BlackmanHarrisWindowSoundTransform.SIX * Math.PI * progress); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/CompositeSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public class CompositeSoundTransform implements SoundTransform { 6 | 7 | private final SoundTransform soundTransform1; 8 | private final SoundTransform soundTransform2; 9 | 10 | public CompositeSoundTransform (final SoundTransform soundTransform11, final SoundTransform soundTransform21) { 11 | this.soundTransform1 = soundTransform11; 12 | this.soundTransform2 = soundTransform21; 13 | } 14 | 15 | @Override 16 | public O transform (final I input) throws SoundTransformException { 17 | return this.soundTransform2.transform (this.soundTransform1.transform (input)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/EightBitsSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | 5 | /** 6 | * Leaves only one sample out of [step] ones, the others are set to 0. The 7 | * effect is to produce a sound that sounds like a video game console. (a good 8 | * step value for a CD format is 25) 9 | */ 10 | public class EightBitsSoundTransform implements SoundTransform { 11 | 12 | private final int step; 13 | 14 | /** 15 | * Default constructor 16 | * 17 | * @param step 18 | * iteration step value 19 | */ 20 | public EightBitsSoundTransform (final int step) { 21 | this.step = step; 22 | } 23 | 24 | @Override 25 | public Channel transform (final Channel input) { 26 | 27 | final Channel outputSound = new Channel (new long [input.getSamplesLength ()], input.getFormatInfo (), input.getChannelNum ()); 28 | for (int i = 0 ; i < input.getSamplesLength () ; i++) { 29 | if (i % this.step == 0) { 30 | outputSound.setSampleAt (i, input.getSampleAt (i)); 31 | } else { 32 | outputSound.setSampleAt (i, 0); 33 | } 34 | } 35 | 36 | return outputSound; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/HammingWindowSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | public final class HammingWindowSoundTransform extends AbstractWindowSoundTransform { 4 | 5 | private static final int TWO = 2; 6 | private static final double COEFF2 = 0.46; 7 | private static final double COEFF1 = 0.54; 8 | 9 | @Override 10 | protected double applyFunction (final double progress) { 11 | return HammingWindowSoundTransform.COEFF1 - HammingWindowSoundTransform.COEFF2 * Math.cos (HammingWindowSoundTransform.TWO * Math.PI * progress); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/HanningWindowSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | public class HanningWindowSoundTransform extends AbstractWindowSoundTransform { 4 | 5 | private static final int TWO = 2; 6 | private static final int ONE = 1; 7 | private static final double COEFF1 = 0.5; 8 | 9 | @Override 10 | protected double applyFunction (final double progress) { 11 | return HanningWindowSoundTransform.COEFF1 * (HanningWindowSoundTransform.ONE - Math.cos (HanningWindowSoundTransform.TWO * Math.PI * progress)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/LoopSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | /** 8 | * Repeats a sound as another sound 9 | * 10 | */ 11 | public class LoopSoundTransform implements SoundTransform { 12 | 13 | enum LoopSoundTransformErrorCode implements ErrorCode { 14 | NOT_POSITIVE_VALUE ("The specified length is not positive (%1d)"); 15 | 16 | private String messageFormat; 17 | 18 | LoopSoundTransformErrorCode (final String mF) { 19 | this.messageFormat = mF; 20 | } 21 | 22 | @Override 23 | public String getMessageFormat () { 24 | return this.messageFormat; 25 | } 26 | 27 | } 28 | 29 | private final int length; 30 | 31 | /** 32 | * Default constructor 33 | * 34 | * @param length1 35 | * length (in samples) of the repetition(s) 36 | */ 37 | public LoopSoundTransform (final int length1) { 38 | this.length = length1; 39 | } 40 | 41 | @Override 42 | public Channel transform (final Channel input) throws SoundTransformException { 43 | final Channel result = new Channel (new long [this.length], input.getFormatInfo (), input.getChannelNum ()); 44 | 45 | if (this.length <= 0) { 46 | throw new SoundTransformException (LoopSoundTransformErrorCode.NOT_POSITIVE_VALUE, new IllegalArgumentException (), 0, this.length); 47 | } 48 | 49 | for (int i = 0 ; i < this.length ; i++) { 50 | result.setSampleAt (i, input.getSampleAt (i % input.getSamplesLength ())); 51 | } 52 | return result; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/NoOpSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | 5 | /** 6 | * Produces an exact copy of the input sound 7 | * 8 | */ 9 | public class NoOpSoundTransform implements SoundTransform { 10 | 11 | public NoOpSoundTransform () { 12 | } 13 | 14 | private Channel noop (final Channel sound) { 15 | 16 | // same array in newdata 17 | final long [] newdata = new long [sound.getSamplesLength ()]; 18 | 19 | sound.copyTo (newdata); 20 | 21 | return new Channel (newdata, sound.getFormatInfo (), sound.getChannelNum ()); 22 | } 23 | 24 | @Override 25 | public Channel transform (final Channel input) { 26 | return this.noop (input); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/NoOpWindowSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | public class NoOpWindowSoundTransform extends AbstractWindowSoundTransform { 4 | 5 | @Override 6 | protected double applyFunction (final double progress) { 7 | return 1; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/PeakFindSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 6 | import org.toilelibre.libe.soundtransform.model.logging.EventCode; 7 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 8 | import org.toilelibre.libe.soundtransform.model.logging.LogEvent.LogLevel; 9 | 10 | public interface PeakFindSoundTransform> extends SoundTransform, LogAware { 11 | 12 | public enum PeakFindSoundTransformEventCode implements EventCode { 13 | 14 | ITERATION_IN_PROGRESS (LogLevel.VERBOSE, "Iteration #%1d/%2d, %3d%%"); 15 | 16 | private final String messageFormat; 17 | private final LogLevel logLevel; 18 | 19 | PeakFindSoundTransformEventCode (final LogLevel ll, final String mF) { 20 | this.messageFormat = mF; 21 | this.logLevel = ll; 22 | } 23 | 24 | @Override 25 | public LogLevel getLevel () { 26 | return this.logLevel; 27 | } 28 | 29 | @Override 30 | public String getMessageFormat () { 31 | return this.messageFormat; 32 | } 33 | } 34 | 35 | float getDetectedNoteVolume (); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/PitchSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | 5 | /** 6 | * Removes or adds some samples in the input sound according to the passed 7 | * percent parameter. This will change the pitch of the sound (the frequencies 8 | * will be shifted) 9 | */ 10 | public class PitchSoundTransform implements SoundTransform { 11 | 12 | private static final float A_HUNDRED = 100; 13 | private final float percent; 14 | 15 | /** 16 | * Default constructor 17 | * 18 | * @param percent1 19 | * if < 100, the sound will contains more samples, therefore 20 | * the sound will be pitched down, and the frequencies will be 21 | * lowered if = 100, nothing happens if > 100, the sound will 22 | * contains less samples, therefore the sound will be pitched up, 23 | * and the frequencies will be higher 24 | */ 25 | public PitchSoundTransform (final float percent1) { 26 | this.percent = percent1; 27 | } 28 | 29 | private Channel pitch (final Channel sound, final float percent1) { 30 | final float total = PitchSoundTransform.A_HUNDRED; 31 | if (percent1 == total) { 32 | return sound; 33 | } 34 | final float nbSamples = sound.getSamplesLength (); 35 | final float nbFiltered = Math.abs (total * nbSamples / percent1); 36 | final float incr = nbSamples / nbFiltered; 37 | 38 | final long [] ret = new long [(int) nbFiltered]; 39 | for (double i = 0 ; i < incr * nbFiltered ; i += incr) { 40 | final int j = (int) (i / incr); 41 | if (j < ret.length) { 42 | ret [j] = sound.getSampleAt ((int) i); 43 | } 44 | } 45 | return new Channel (ret, sound.getFormatInfo (), sound.getChannelNum ()); 46 | } 47 | 48 | @Override 49 | public Channel transform (final Channel input) { 50 | return this.pitch (input, this.percent); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/ReverseSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | 5 | /** 6 | * Make a new sound such as newsoundsamples [i] = soundsamples [length - i] 7 | * 8 | */ 9 | public class ReverseSoundTransform implements SoundTransform { 10 | 11 | /** 12 | * Default constructor 13 | */ 14 | public ReverseSoundTransform () { 15 | } 16 | 17 | private Channel reverse (final Channel sound) { 18 | 19 | final long [] newdata = new long [sound.getSamplesLength ()]; 20 | // this is the raw audio data -- no header 21 | 22 | for (int i = 0 ; i < sound.getSamplesLength () ; i++) { 23 | newdata [i] = sound.getSampleAt (sound.getSamplesLength () - i - 1); 24 | } 25 | // normalized result in newdata 26 | return new Channel (newdata, sound.getFormatInfo (), sound.getChannelNum ()); 27 | } 28 | 29 | @Override 30 | public Channel transform (final Channel input) { 31 | return this.reverse (input); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/SoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public interface SoundTransform { 6 | 7 | U transform (T input) throws SoundTransformException; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/sound/transform/UseWindowFunctionSoundTransform.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.sound.transform; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | /** 7 | * 8 | * Proxy transform to pass a Window Transform and apply on a whole Channel 9 | * 10 | */ 11 | public class UseWindowFunctionSoundTransform implements SoundTransform { 12 | 13 | private final AbstractWindowSoundTransform windowFunction; 14 | 15 | /** 16 | * 17 | * @param windowFunction1 18 | * nested window transform 19 | */ 20 | public UseWindowFunctionSoundTransform (final AbstractWindowSoundTransform windowFunction1) { 21 | this.windowFunction = windowFunction1; 22 | } 23 | 24 | @Override 25 | public Channel transform (final Channel input) throws SoundTransformException { 26 | return this.windowFunction.transformWholeChannel (input); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/DefaultSpectrumToStringService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | 5 | @Service 6 | final class DefaultSpectrumToStringService implements SpectrumToStringService { 7 | 8 | private final SpectrumToStringHelper spectrumHelper; 9 | 10 | public DefaultSpectrumToStringService (final SpectrumToStringHelper helper1) { 11 | this.spectrumHelper = helper1; 12 | } 13 | 14 | /* 15 | * (non-Javadoc) 16 | * 17 | * @see org.toilelibre.libe.soundtransform.model.converted.spectrum. 18 | * Spectrum2StringHelper 19 | * #convert(org.toilelibre.libe.soundtransform.model.converted 20 | * .spectrum.Spectrum) 21 | */ 22 | @Override 23 | public String convert (final Spectrum spectrum) { 24 | return this.spectrumHelper.fsToString (spectrum); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/FourierTransformHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.AbstractFrequencySoundTransform; 7 | 8 | public interface FourierTransformHelper { 9 | 10 | Channel reverse (Spectrum spectrum); 11 | 12 | Channel transform (AbstractFrequencySoundTransform st, Channel sound); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/Spectrum.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 6 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 7 | 8 | public class Spectrum implements Serializable { 9 | 10 | private static final long serialVersionUID = -4609743181877386829L; 11 | 12 | private final T state; 13 | private final FormatInfo formatInfo; 14 | 15 | public Spectrum (final T state1, final FormatInfo formatInfo1) { 16 | super (); 17 | this.state = state1; 18 | this.formatInfo = formatInfo1; 19 | } 20 | 21 | public FormatInfo getFormatInfo () { 22 | return this.formatInfo; 23 | } 24 | 25 | public float getSampleRate () { 26 | return this.formatInfo.getSampleRate (); 27 | } 28 | 29 | public int getSampleSize () { 30 | return this.formatInfo.getSampleSize (); 31 | } 32 | 33 | public T getState () { 34 | return this.state; 35 | } 36 | 37 | @SuppressWarnings ("unchecked") 38 | @Override 39 | public String toString () { 40 | return $.select (SpectrumToStringService.class).convert (this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/SpectrumAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.SoundAccessor; 4 | 5 | public abstract class SpectrumAccessor extends SoundAccessor { 6 | 7 | public SpectrumAccessor () { 8 | super (); 9 | this.usedImpls.put (SpectrumToStringService.class, DefaultSpectrumToStringService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/SpectrumHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | public interface SpectrumHelper { 4 | 5 | float freqFromSampleRate (float freq, int sqr2length, float sampleRate); 6 | 7 | int getMaxIndex (Spectrum fs, int min, int max); 8 | 9 | double getMaxValue (Spectrum fs, int min, int max); 10 | 11 | int getFirstPeak (Spectrum fs, int min, int max, double thresholdValue); 12 | 13 | Spectrum productOfMultiples (Spectrum fs, int factor, float partOfTheSpectrumToRead); 14 | 15 | int getLengthOfSpectrum (Spectrum fs); 16 | 17 | double [] productOfMultiples (double [][] spectrumAsDoubles, float sampleRate, int hpsfactor, float partOfTheSpectrumToRead); 18 | 19 | int getMaxIndex (double [] array, int min, int max); 20 | 21 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/SpectrumToCepstrumHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | public interface SpectrumToCepstrumHelper { 4 | Spectrum spectrumToCepstrum (Spectrum fs); 5 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/SpectrumToStringHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | public interface SpectrumToStringHelper { 4 | 5 | String fsToString (Spectrum fs); 6 | 7 | String fsToString (Spectrum fs, int low, int high, int compression, int height); 8 | 9 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/converted/spectrum/SpectrumToStringService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.converted.spectrum; 2 | 3 | import org.toilelibre.libe.soundtransform.model.Service; 4 | 5 | @Service 6 | interface SpectrumToStringService { 7 | 8 | String convert (Spectrum spectrum); 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/exception/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.exception; 2 | 3 | public interface ErrorCode { 4 | String getMessageFormat (); 5 | 6 | String name (); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/exception/SoundTransformException.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.exception; 2 | 3 | public class SoundTransformException extends Exception { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = 2154130846010299931L; 8 | private final ErrorCode errorCode; 9 | private final Object [] args; 10 | 11 | public SoundTransformException (final ErrorCode errorCode, final Exception cause, final Object... args) { 12 | super (cause); 13 | this.errorCode = errorCode; 14 | this.args = args; 15 | } 16 | 17 | public ErrorCode getErrorCode () { 18 | return this.errorCode; 19 | } 20 | 21 | @Override 22 | public String getMessage () { 23 | return String.format (this.errorCode.getMessageFormat (), this.args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/exception/SoundTransformRuntimeException.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.exception; 2 | 3 | public class SoundTransformRuntimeException extends RuntimeException { 4 | enum RuntimeErrorCode implements ErrorCode { 5 | RUNTIME_ERROR ("Runtime error"); 6 | 7 | private String messageFormat; 8 | 9 | RuntimeErrorCode (final String mF) { 10 | this.messageFormat = mF; 11 | } 12 | 13 | @Override 14 | public String getMessageFormat () { 15 | return this.messageFormat; 16 | } 17 | 18 | } 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 2154130846010299931L; 24 | private final ErrorCode errorCode; 25 | private final Object [] args; 26 | 27 | public SoundTransformRuntimeException (final ErrorCode errorCode, final Exception cause, final Object... args) { 28 | super (cause); 29 | this.errorCode = errorCode; 30 | this.args = args; 31 | } 32 | 33 | public SoundTransformRuntimeException (final SoundTransformException cause) { 34 | super (cause); 35 | this.errorCode = RuntimeErrorCode.RUNTIME_ERROR; 36 | this.args = new Object [0]; 37 | } 38 | 39 | public ErrorCode getErrorCode () { 40 | return this.errorCode; 41 | } 42 | 43 | @Override 44 | public String getMessage () { 45 | return String.format (this.errorCode.getMessageFormat (), this.args); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/AdjustFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | public interface AdjustFrequenciesProcessor { 4 | 5 | float [] adjust (float [] freqs); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/ChangeOctaveProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | public interface ChangeOctaveProcessor { 4 | 5 | float [] multFreqs (float [] freqs, float factor); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/CompressFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | public interface CompressFrequenciesProcessor { 4 | 5 | float [] compress (float [] array, float factor); 6 | 7 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/FilterFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public interface FilterFrequenciesProcessor { 7 | public enum FilterFrequenciesProcessorErrorCode implements ErrorCode { 8 | 9 | INVALID_RANGE ("Invalid range, high is lower than or equal to low (low=%1f, high=%1f)"); 10 | 11 | private final String messageFormat; 12 | 13 | FilterFrequenciesProcessorErrorCode (final String mF) { 14 | this.messageFormat = mF; 15 | } 16 | 17 | @Override 18 | public String getMessageFormat () { 19 | return this.messageFormat; 20 | } 21 | } 22 | 23 | float [] filter (float [] freqs, float low, float high) throws SoundTransformException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/FreqsAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.SpectrumAccessor; 4 | 5 | public abstract class FreqsAccessor extends SpectrumAccessor { 6 | 7 | public FreqsAccessor () { 8 | super (); 9 | this.usedImpls.put (LoudestFreqsService.class, DefaultLoudestFreqsService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/LoudestFreqsService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | import java.util.List; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | 8 | @Service 9 | public interface LoudestFreqsService { 10 | 11 | List adjust (List freqs); 12 | 13 | List compress (List freqs, float factor); 14 | 15 | List filterRange (List freqs, float low, float high) throws SoundTransformException; 16 | 17 | List insertPart (List freqs, List subFreqs, int start); 18 | 19 | List octaveDown (List freqs); 20 | 21 | List octaveUp (List freqs); 22 | 23 | List replacePart (List freqs, List subFreqs, int start); 24 | 25 | List surroundInRange (List freqs, float low, float high) throws SoundTransformException; 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/ReplaceFrequenciesProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | public interface ReplaceFrequenciesProcessor { 4 | 5 | float [] insertPart (float [] freqs, float [] subFreqs, int start); 6 | 7 | float [] replacePart (float [] freqs, float [] subFreqs, int start); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/freqs/SurroundInRangeProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.freqs; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public interface SurroundInRangeProcessor { 7 | public enum SurroundInRangeProcessorErrorCode implements ErrorCode { 8 | 9 | INVALID_RANGE ("Invalid range, high is lower than or equal to low (low=%1f, high=%1f)"); 10 | 11 | private final String messageFormat; 12 | 13 | SurroundInRangeProcessorErrorCode (final String mF) { 14 | this.messageFormat = mF; 15 | } 16 | 17 | @Override 18 | public String getMessageFormat () { 19 | return this.messageFormat; 20 | } 21 | } 22 | 23 | float [] surroundFreqsInRange (float [] freqs, float low, float high) throws SoundTransformException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/AudioFileService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream; 2 | 3 | import java.io.File; 4 | import java.io.InputStream; 5 | 6 | import org.toilelibre.libe.soundtransform.model.Service; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 9 | 10 | @Service 11 | public interface AudioFileService extends LogAware { 12 | 13 | InputStream streamFromFile (File file) throws SoundTransformException; 14 | 15 | InputStream streamFromRawStream (InputStream is, StreamInfo streamInfo) throws SoundTransformException; 16 | 17 | void fileFromStream (InputStream ais2, File fDest) throws SoundTransformException; 18 | 19 | InputStream streamFromInputStream (InputStream is) throws SoundTransformException; 20 | 21 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/InputStreamAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream; 2 | 3 | import org.toilelibre.libe.soundtransform.model.freqs.FreqsAccessor; 4 | 5 | public abstract class InputStreamAccessor extends FreqsAccessor { 6 | 7 | public InputStreamAccessor () { 8 | super (); 9 | this.usedImpls.put (AudioFileService.class, DefaultAudioFileService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/convert/ConvertAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.convert; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.InputStreamAccessor; 4 | 5 | public abstract class ConvertAccessor extends InputStreamAccessor { 6 | 7 | public ConvertAccessor () { 8 | super (); 9 | this.usedImpls.put (FormatConvertService.class, GuessConverterFormatConvertService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/convert/ConvertProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.convert; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | public interface ConvertProcessor { 8 | InputStream convertToWavStream (final ConverterLauncher launcher, final InputStream inputStream, final String fileName) throws SoundTransformException; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/convert/ConverterLauncher.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.convert; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.InputStream; 5 | import java.util.Map.Entry; 6 | 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | 10 | public interface ConverterLauncher { 11 | 12 | Entry convert (T converter, InputStream inputStream) throws SoundTransformException; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/convert/FormatConvertService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.convert; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 8 | 9 | @Service 10 | public interface FormatConvertService extends LogAware { 11 | 12 | InputStream convertToWav (InputStream compressedInputStream, String fileName) throws SoundTransformException; 13 | 14 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/convert/GuessConverterFormatConvertService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.convert; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.logging.AbstractLogAware; 8 | 9 | @Service 10 | final class GuessConverterFormatConvertService extends AbstractLogAware implements FormatConvertService> { 11 | 12 | private final ConvertProcessor convertProcessor; 13 | private final ConverterLauncher converterLauncher; 14 | 15 | public GuessConverterFormatConvertService (final ConvertProcessor convertProcessor1, final ConverterLauncher converterLauncher1) { 16 | this.convertProcessor = convertProcessor1; 17 | this.converterLauncher = converterLauncher1; 18 | } 19 | 20 | @Override 21 | public InputStream convertToWav (final InputStream compressedInputStream, final String fileName) throws SoundTransformException { 22 | return this.convertProcessor.convertToWavStream (this.converterLauncher, compressedInputStream, fileName); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/format/AudioFormatParser.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.format; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 8 | 9 | public interface AudioFormatParser { 10 | enum AudioFormatParserErrorCode implements ErrorCode { 11 | 12 | WRONG_TYPE ("incorrect stream type"), READ_ERROR ("Could not parse the format of the stream"); 13 | 14 | private final String messageFormat; 15 | 16 | AudioFormatParserErrorCode (final String mF) { 17 | this.messageFormat = mF; 18 | } 19 | 20 | @Override 21 | public String getMessageFormat () { 22 | return this.messageFormat; 23 | } 24 | } 25 | 26 | Object audioFormatfromStreamInfo (StreamInfo info); 27 | 28 | StreamInfo fromAudioFormat (Object audioFormat1, long l) throws SoundTransformException; 29 | 30 | StreamInfo getStreamInfo (InputStream ais) throws SoundTransformException; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/format/AudioFormatService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.format; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 8 | 9 | @Service 10 | public interface AudioFormatService { 11 | Object audioFormatfromStreamInfo (StreamInfo info); 12 | 13 | StreamInfo fromAudioFormat (Object audioFormat1, long l) throws SoundTransformException; 14 | 15 | StreamInfo getStreamInfo (InputStream ais) throws SoundTransformException; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/format/DefaultAudioFormatService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.format; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 8 | 9 | @Service 10 | final class DefaultAudioFormatService implements AudioFormatService { 11 | 12 | private final AudioFormatParser parser; 13 | 14 | public DefaultAudioFormatService (final AudioFormatParser parser1) { 15 | this.parser = parser1; 16 | } 17 | 18 | @Override 19 | public Object audioFormatfromStreamInfo (final StreamInfo info) { 20 | return this.parser.audioFormatfromStreamInfo (info); 21 | } 22 | 23 | @Override 24 | public StreamInfo fromAudioFormat (final Object audioFormat1, final long l) throws SoundTransformException { 25 | return this.parser.fromAudioFormat (audioFormat1, l); 26 | } 27 | 28 | @Override 29 | public StreamInfo getStreamInfo (final InputStream ais) throws SoundTransformException { 30 | return this.parser.getStreamInfo (ais); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/format/FormatAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.format; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.convert.ConvertAccessor; 4 | 5 | public abstract class FormatAccessor extends ConvertAccessor { 6 | 7 | public FormatAccessor () { 8 | super (); 9 | this.usedImpls.put (AudioFormatService.class, DefaultAudioFormatService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/fromsound/FromSoundAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.fromsound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.format.FormatAccessor; 4 | 5 | public abstract class FromSoundAccessor extends FormatAccessor { 6 | 7 | public FromSoundAccessor () { 8 | super (); 9 | this.usedImpls.put (SoundToInputStreamService.class, DefaultSoundToInputStreamService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/fromsound/SoundToInputStreamService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.fromsound; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 10 | 11 | @Service 12 | public interface SoundToInputStreamService extends LogAware { 13 | 14 | InputStream toStream (Sound sound, StreamInfo streamInfo) throws SoundTransformException; 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/readsound/InputStreamToByteArrayHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.readsound; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | public interface InputStreamToByteArrayHelper { 8 | 9 | byte [] convertToByteArray (InputStream is) throws SoundTransformException; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/readsound/InputStreamToSoundService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.readsound; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 8 | import org.toilelibre.libe.soundtransform.model.logging.EventCode; 9 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 10 | import org.toilelibre.libe.soundtransform.model.logging.LogEvent.LogLevel; 11 | 12 | public interface InputStreamToSoundService extends LogAware { 13 | public enum TransformInputStreamServiceEventCode implements EventCode { 14 | CONVERT_INTO_JAVA_OBJECT (LogLevel.INFO, "Converting input into java object"), CONVERT_DONE (LogLevel.INFO, "Done converting the input stream"); 15 | 16 | private final String messageFormat; 17 | private final LogLevel logLevel; 18 | 19 | TransformInputStreamServiceEventCode (final LogLevel ll, final String mF) { 20 | this.logLevel = ll; 21 | this.messageFormat = mF; 22 | } 23 | 24 | /* 25 | * (non-Javadoc) 26 | * 27 | * @see 28 | * org.toilelibre.libe.soundtransform.model.inputstream.InputStreamToSound 29 | * #getLevel() 30 | */ 31 | @Override 32 | public LogLevel getLevel () { 33 | return this.logLevel; 34 | } 35 | 36 | /* 37 | * (non-Javadoc) 38 | * 39 | * @see 40 | * org.toilelibre.libe.soundtransform.model.inputstream.InputStreamToSound 41 | * #getMessageFormat() 42 | */ 43 | @Override 44 | public String getMessageFormat () { 45 | return this.messageFormat; 46 | } 47 | } 48 | 49 | Sound fromInputStream (InputStream ais) throws SoundTransformException; 50 | 51 | Sound fromInputStream (InputStream ais, StreamInfo isInfo) throws SoundTransformException; 52 | 53 | StreamInfo getStreamInfo (InputStream ais) throws SoundTransformException; 54 | 55 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/inputstream/readsound/ReadSoundAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.inputstream.readsound; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.fromsound.FromSoundAccessor; 4 | 5 | public abstract class ReadSoundAccessor extends FromSoundAccessor { 6 | 7 | public ReadSoundAccessor () { 8 | super (); 9 | this.usedImpls.put (InputStreamToSoundService.class, DefaultInputStreamToSoundService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/Library.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.toilelibre.libe.soundtransform.model.library.pack.Pack; 7 | 8 | public class Library { 9 | 10 | private final Map packs; 11 | 12 | public Library () { 13 | this.packs = new HashMap (); 14 | } 15 | 16 | public void addPack (final String name, final Pack p) { 17 | this.packs.put (name, p); 18 | } 19 | 20 | public Pack getPack (final String name) { 21 | return this.packs.get (name); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/ContextLoader.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | 7 | public interface ContextLoader { 8 | 9 | InputStream read (Object context, int id) throws SoundTransformException; 10 | 11 | InputStream read (Object context, Class rClass, String idName) throws SoundTransformException; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/Pack.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 6 | 7 | public class Pack extends HashMap { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = -7834749756288316057L; 13 | 14 | @Override 15 | public String toString () { 16 | return $.select (PackToStringHelper.class).toString (this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/PackAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.ReadSoundAccessor; 4 | 5 | public abstract class PackAccessor extends ReadSoundAccessor { 6 | 7 | public PackAccessor () { 8 | super (); 9 | this.usedImpls.put (AddNoteService.class, DefaultAddNoteService.class); 10 | this.usedImpls.put (ImportPackService.class, DefaultImportPackService.class); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/PackConfigParser.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public interface PackConfigParser { 7 | 8 | Map>> parse (String input); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/PackToStringHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import org.toilelibre.libe.soundtransform.model.library.pack.note.Note; 4 | 5 | public interface PackToStringHelper { 6 | 7 | String toString (Range range); 8 | 9 | String toString (Note note); 10 | 11 | String toString (Pack pack); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/Range.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 6 | import org.toilelibre.libe.soundtransform.model.library.pack.note.Note; 7 | 8 | public class Range extends HashMap { 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 6526477231719258055L; 14 | 15 | public Note getNearestNote (final int frequency) { 16 | float nearest = Integer.MIN_VALUE; 17 | for (final Float i : this.keySet ()) { 18 | if (Math.abs (frequency - i) < Math.abs (frequency - nearest)) { 19 | nearest = i; 20 | } 21 | } 22 | return this.get (Float.valueOf (nearest)); 23 | } 24 | 25 | @Override 26 | public String toString () { 27 | return $.select (PackToStringHelper.class).toString (this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/ADSRHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 4 | 5 | public interface ADSRHelper { 6 | 7 | int findDecay (final double [] magnitudeArray, int attack) throws SoundTransformException; 8 | 9 | int findRelease (final double [] magnitudeArray) throws SoundTransformException; 10 | 11 | int findSustain (final double [] magnitudeArray, int decay) throws SoundTransformException; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/ComputedChordNote.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | final class ComputedChordNote extends FormulaNote { 4 | 5 | private static final int PARTS = 12; 6 | private static final int HALF = ComputedChordNote.PARTS / 2; 7 | private static final float FIRST_COEFF = 0.3f; 8 | private static final float SECOND_COEFF = 0.2f; 9 | private static final float THIRD_COEFF = 0.4f; 10 | private static final float TWO_PI = (float) (2 * Math.PI); 11 | 12 | @Override 13 | protected float applyFormula (final int j, final float frequency, final float sampleRate) { 14 | return this.sinOnceOtherXTimes (j, frequency, sampleRate, ComputedChordNote.PARTS, 0) * ComputedChordNote.FIRST_COEFF + this.sinOnceOtherXTimes (j, frequency, sampleRate, ComputedChordNote.PARTS, ComputedChordNote.HALF) * ComputedChordNote.SECOND_COEFF 15 | + this.sinOnceOtherXTimes (j, frequency, sampleRate, 1, 0) * ComputedChordNote.THIRD_COEFF; 16 | } 17 | 18 | @Override 19 | public String getName () { 20 | return this.getClass ().getName (); 21 | } 22 | 23 | private float sinOnceOtherXTimes (final int j, final float frequency, final float sampleRate, final int xTimes, final int modulo) { 24 | return (float) (Math.round (j * frequency / sampleRate) % xTimes == modulo ? Math.sin (j * frequency * ComputedChordNote.TWO_PI / sampleRate) : 0); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/ComputedOrganNote.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | final class ComputedOrganNote extends FormulaNote { 4 | 5 | private static final float TWO_PI = (float) (2 * Math.PI); 6 | private static final float FIRST_COEFF = 0.12f; 7 | private static final float SECOND_COEFF = 0.25f; 8 | private static final float THIRD_COEFF = 0.5f; 9 | private static final float FOURTH_COEFF = 0.5f; 10 | private static final float ONCE = 1; 11 | private static final float TWICE = 2; 12 | private static final float FOUR_TIMES = 4; 13 | private static final float EIGHT_TIMES = 8; 14 | private static final float NO_GAP = 0; 15 | private static final float ONE_FOURTH_GAP = (float) Math.PI / 2; 16 | private static final float HALF_GAP = (float) Math.PI; 17 | private static final float THREE_FOURTH_GAP = (float) (3 * Math.PI / 2); 18 | 19 | @Override 20 | protected float applyFormula (final int j, final float frequency, final float sampleRate) { 21 | return (float) (Math.sin (j * ComputedOrganNote.ONCE * frequency * ComputedOrganNote.TWO_PI / sampleRate + ComputedOrganNote.NO_GAP) * ComputedOrganNote.FIRST_COEFF 22 | + Math.sin (j * ComputedOrganNote.TWICE * frequency * ComputedOrganNote.TWO_PI / sampleRate + ComputedOrganNote.ONE_FOURTH_GAP) * ComputedOrganNote.SECOND_COEFF 23 | + Math.sin (j * ComputedOrganNote.FOUR_TIMES * frequency * ComputedOrganNote.TWO_PI / sampleRate + ComputedOrganNote.HALF_GAP) * ComputedOrganNote.THIRD_COEFF + Math.sin (j * ComputedOrganNote.EIGHT_TIMES * frequency * ComputedOrganNote.TWO_PI / sampleRate 24 | + ComputedOrganNote.THREE_FOURTH_GAP) 25 | * ComputedOrganNote.FOURTH_COEFF); 26 | 27 | } 28 | 29 | @Override 30 | public String getName () { 31 | return this.getClass ().getName (); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/FrequencyHelper.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public interface FrequencyHelper { 7 | float findFrequency (Sound sound) throws SoundTransformException; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/Note.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public interface Note { 7 | 8 | Channel getAttack (float frequency, int channelnum, float lengthInSeconds) throws SoundTransformException; 9 | 10 | Channel getDecay (float frequency, int channelnum, float lengthInSeconds) throws SoundTransformException; 11 | 12 | float getFrequency (); 13 | 14 | String getName (); 15 | 16 | Channel getRelease (float frequency, int channelnum, float lengthInSeconds) throws SoundTransformException; 17 | 18 | Channel getSustain (float frequency, int channelnum, float lengthInSeconds) throws SoundTransformException; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/NoteAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.library.pack.PackAccessor; 4 | 5 | public abstract class NoteAccessor extends PackAccessor { 6 | 7 | public NoteAccessor () { 8 | super (); 9 | this.usedImpls.put (SoundToNoteService.class, DefaultSoundToNoteService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/PureNote.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | final class PureNote extends FormulaNote { 4 | 5 | private static final float TWO_PI = (float) (2 * Math.PI); 6 | 7 | @Override 8 | protected float applyFormula (final int j, final float frequency, final float sampleRate) { 9 | return (float) Math.sin (j * frequency * PureNote.TWO_PI / sampleRate); 10 | } 11 | 12 | @Override 13 | public String getName () { 14 | return this.getClass ().getName (); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/Silence.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 4 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 5 | 6 | public class Silence implements Note { 7 | 8 | private static final float ONE_FOURTH = 1.0f / 4; 9 | private static final int DEFAULT_NB_BYTES = 2; 10 | private static final int SAMPLE_RATE = 48000; 11 | 12 | private Channel generateSilence (final float lengthInSeconds) { 13 | final int nbSamples = (int) (Silence.SAMPLE_RATE * lengthInSeconds * 1.0); 14 | return new Channel (new long [nbSamples], new FormatInfo (Silence.DEFAULT_NB_BYTES, Silence.SAMPLE_RATE), 0); 15 | } 16 | 17 | @Override 18 | public Channel getAttack (final float frequency, final int channelnum, final float lengthInSeconds) { 19 | return this.generateSilence (Silence.ONE_FOURTH * lengthInSeconds); 20 | } 21 | 22 | @Override 23 | public Channel getDecay (final float frequency, final int channelnum, final float lengthInSeconds) { 24 | return this.generateSilence (Silence.ONE_FOURTH * lengthInSeconds); 25 | } 26 | 27 | @Override 28 | public float getFrequency () { 29 | return 0; 30 | } 31 | 32 | @Override 33 | public String getName () { 34 | return "SILENCE"; 35 | } 36 | 37 | @Override 38 | public Channel getRelease (final float frequency, final int channelnum, final float lengthInSeconds) { 39 | return this.generateSilence (Silence.ONE_FOURTH * lengthInSeconds); 40 | } 41 | 42 | @Override 43 | public Channel getSustain (final float frequency, final int channelnum, final float lengthInSeconds) { 44 | return this.generateSilence (Silence.ONE_FOURTH * lengthInSeconds); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/SoundToNoteService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public interface SoundToNoteService { 7 | 8 | Note convert (SimpleNoteInfo noteInfo, Sound sound) throws SoundTransformException; 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/library/pack/note/TechnicalInstrument.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack.note; 2 | 3 | public enum TechnicalInstrument { 4 | 5 | PURE_NOTE (new PureNote ()), COMPUTED_ORGAN_NOTE (new ComputedOrganNote ()), COMPUTED_CHORD_NOTE (new ComputedChordNote ()); 6 | 7 | private Note note; 8 | 9 | TechnicalInstrument (final Note note1) { 10 | this.note = note1; 11 | } 12 | 13 | public static TechnicalInstrument of (final String clazzName) { 14 | for (final TechnicalInstrument instrument : TechnicalInstrument.values ()) { 15 | if (instrument.note.getName ().equals (clazzName)) { 16 | return instrument; 17 | } 18 | } 19 | return null; 20 | } 21 | 22 | public Note getUniformNote () { 23 | return this.note; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/AbstractLogAware.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | public class AbstractLogAware> implements LogAware> { 4 | 5 | protected Observer [] observers; 6 | 7 | @Override 8 | public void log (final LogEvent event) { 9 | if (this.observers == null) { 10 | return; 11 | } 12 | for (final Observer observer : this.observers) { 13 | observer.notify (event); 14 | } 15 | } 16 | 17 | @Override 18 | @SuppressWarnings ("unchecked") 19 | public T setObservers (final Observer... observers1) { 20 | this.observers = observers1; 21 | return (T) this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/EventCode.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | import org.toilelibre.libe.soundtransform.model.logging.LogEvent.LogLevel; 4 | 5 | public interface EventCode { 6 | 7 | LogLevel getLevel (); 8 | 9 | String getMessageFormat (); 10 | 11 | String name (); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/LogAware.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | public interface LogAware { 4 | 5 | void log (LogEvent event); 6 | 7 | T setObservers (Observer... observers); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/LogEvent.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.Locale; 6 | 7 | public class LogEvent { 8 | 9 | public enum LogLevel { 10 | PARANOIAC, VERBOSE, INFO, WARN, ERROR 11 | } 12 | 13 | private final EventCode eventCode; 14 | 15 | private final Date date; 16 | 17 | private final Object [] params; 18 | 19 | public LogEvent (final EventCode eventCode, final Object... params1) { 20 | this.eventCode = eventCode; 21 | this.date = new Date (); 22 | this.params = params1; 23 | } 24 | 25 | private String getDateInIso8601Format () { 26 | return new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", Locale.US).format (this.date); 27 | } 28 | 29 | public EventCode getEventCode () { 30 | return this.eventCode; 31 | } 32 | 33 | public LogLevel getLevel () { 34 | return this.eventCode.getLevel (); 35 | } 36 | 37 | public String getMsg () { 38 | return String.format (this.eventCode.getMessageFormat (), this.params); 39 | } 40 | 41 | @Override 42 | public String toString () { 43 | return this.getDateInIso8601Format () + " [" + this.eventCode.getLevel () + "," + this.eventCode.name () + "] " + this.getMsg (); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/Observer.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | public interface Observer extends Cloneable { 4 | 5 | void notify (LogEvent logEvent); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/logging/TextLogEvent.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.logging; 2 | 3 | public class TextLogEvent extends LogEvent { 4 | 5 | public enum NoEventCode implements EventCode { 6 | PLAIN_TEXT_EVENT; 7 | 8 | @Override 9 | public LogLevel getLevel () { 10 | return LogLevel.INFO; 11 | } 12 | 13 | @Override 14 | public String getMessageFormat () { 15 | return "%1s"; 16 | } 17 | } 18 | 19 | public TextLogEvent (final String msg) { 20 | super (NoEventCode.PLAIN_TEXT_EVENT, msg); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/play/PlayAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.play; 2 | 3 | import org.toilelibre.libe.soundtransform.model.library.pack.note.NoteAccessor; 4 | 5 | public abstract class PlayAccessor extends NoteAccessor { 6 | 7 | public PlayAccessor () { 8 | super (); 9 | this.usedImpls.put (PlayObjectService.class, DefaultPlayObjectService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/play/PlayObjectException.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.play; 2 | 3 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public class PlayObjectException extends SoundTransformException { 7 | 8 | public enum PlaySoundErrorCode implements ErrorCode { 9 | COULD_NOT_PLAY_SOUND ("Could not play a sound"); 10 | private final String messageFormat; 11 | 12 | PlaySoundErrorCode (final String mF) { 13 | this.messageFormat = mF; 14 | } 15 | 16 | @Override 17 | public String getMessageFormat () { 18 | return this.messageFormat; 19 | } 20 | } 21 | 22 | /** 23 | * 24 | */ 25 | private static final long serialVersionUID = -4904836048288493711L; 26 | 27 | public PlayObjectException (final Exception e) { 28 | super (PlaySoundErrorCode.COULD_NOT_PLAY_SOUND, e); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/play/PlayObjectProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.play; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 6 | 7 | public interface PlayObjectProcessor { 8 | 9 | Object play (InputStream ais, StreamInfo streamInfo, Object stopMonitor, int skipMilliSeconds) throws PlayObjectException; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/play/PlayObjectService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.play; 2 | 3 | import java.io.InputStream; 4 | import java.io.Serializable; 5 | 6 | import org.toilelibre.libe.soundtransform.model.Service; 7 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 8 | import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | 11 | @Service 12 | public interface PlayObjectService { 13 | 14 | Object play (InputStream is, Object stopMonitor, int skipMilliSeconds) throws SoundTransformException; 15 | 16 | Object play (Sound sound, Object stopMonitor, int skipMilliSeconds) throws SoundTransformException; 17 | 18 | Object play (Spectrum spectrum, Object stopMonitor, int skipMilliSeconds) throws SoundTransformException; 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/AmplitudeObserver.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record; 2 | 3 | public interface AmplitudeObserver { 4 | 5 | void update (float soundLevel); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/RecordAccessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record; 2 | 3 | import org.toilelibre.libe.soundtransform.model.play.PlayAccessor; 4 | 5 | public abstract class RecordAccessor extends PlayAccessor { 6 | 7 | public RecordAccessor () { 8 | super (); 9 | this.usedImpls.put (RecordSoundService.class, DefaultRecordSoundService.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/RecordSoundProcessor.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record; 2 | 3 | import java.io.InputStream; 4 | import java.nio.ByteBuffer; 5 | 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | 8 | public interface RecordSoundProcessor { 9 | 10 | InputStream recordRawInputStream (Object audioFormat, Object stop) throws SoundTransformException; 11 | 12 | ByteBuffer startRecordingAndReturnByteBuffer (Object audioFormat, Object stop) throws SoundTransformException; 13 | 14 | void stopProperly (Object stop) throws SoundTransformException; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/RecordSoundService.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.toilelibre.libe.soundtransform.model.Service; 6 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | import org.toilelibre.libe.soundtransform.model.logging.LogAware; 10 | 11 | @Service 12 | public interface RecordSoundService extends LogAware { 13 | 14 | InputStream recordRawInputStream (StreamInfo streamInfo, Object stop) throws SoundTransformException; 15 | 16 | InputStream recordLimitedTimeRawInputStream (StreamInfo streamInfo) throws SoundTransformException; 17 | 18 | Sound startRecordingASound (StreamInfo streamInfo, AmplitudeObserver amplitudeObserver, Object stop) throws SoundTransformException; 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/exporter/BytesExporterFromThread.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record.exporter; 2 | 3 | public interface BytesExporterFromThread { 4 | 5 | void init (int bufferSize); 6 | 7 | int getReportedBufferSize (); 8 | 9 | void export (byte [] byteArray, int readSize); 10 | 11 | T getOutput (); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/exporter/OutputAsByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record.exporter; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | 5 | public interface OutputAsByteArrayOutputStream extends BytesExporterFromThread { 6 | ByteArrayOutputStream getOutput (); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/toilelibre/libe/soundtransform/model/record/exporter/OutputAsByteBuffer.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.record.exporter; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public interface OutputAsByteBuffer extends BytesExporterFromThread { 6 | ByteBuffer getOutput (); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/raw/apiano3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/apiano3.wav -------------------------------------------------------------------------------- /src/main/resources/raw/apiano4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/apiano4.wav -------------------------------------------------------------------------------- /src/main/resources/raw/defaultpackjavax.json: -------------------------------------------------------------------------------- 1 | { 2 | "simple_piano" : 3 | [ 4 | {"name" : "piano1c.wav"}, 5 | {"name" : "piano3e.wav"}, 6 | {"name" : "piano5g.wav"}, 7 | {"name" : "piano7b.wav"}, 8 | {"name" : "piano2d.wav"}, 9 | {"name" : "piano4f.wav"}, 10 | {"name" : "piano6a.wav"}, 11 | {"name" : "piano8c.wav"} 12 | ], 13 | "g-piano" : 14 | [ 15 | {"name" : "gpiano1.wav"}, 16 | {"name" : "gpiano2.wav"}, 17 | {"name" : "gpiano3.wav"}, 18 | {"name" : "gpiano4.wav"}, 19 | {"name" : "gpiano5.wav"}, 20 | {"name" : "gpiano6.wav"} 21 | ], 22 | "chord_piano" : 23 | [ 24 | {"name" : "gpiano3.wav", 25 | "frequency" : 329, 26 | "attack" : 0, 27 | "decay" : 0, 28 | "sustain" : 0, 29 | "release" : 0}, 30 | {"name" : "gpiano4.wav", 31 | "frequency" : 293, 32 | "attack" : 0, 33 | "decay" : 0, 34 | "sustain" : 0, 35 | "release" : 0} 36 | ], 37 | "org.toilelibre.libe.soundtransform.model.library.pack.note.PureNote" : [], 38 | "org.toilelibre.libe.soundtransform.model.library.pack.note.ComputedOrganNote" : [], 39 | "org.toilelibre.libe.soundtransform.model.library.pack.note.ComputedChordNote" : [] 40 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano1.wav -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano2.wav -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano3.wav -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano4.wav -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano5.wav -------------------------------------------------------------------------------- /src/main/resources/raw/gpiano6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/gpiano6.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano1c.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano1c.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano2d.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano2d.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano3e.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano3e.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano4f.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano4f.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano5g.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano5g.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano6a.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano6a.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano7b.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano7b.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano8c.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano8c.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano_a.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano_a.wav -------------------------------------------------------------------------------- /src/main/resources/raw/piano_low.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/main/resources/raw/piano_low.wav -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/AudioFormatParserTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 5 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 6 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 7 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 8 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 9 | import org.toilelibre.libe.soundtransform.model.inputstream.format.AudioFormatParser; 10 | 11 | public class AudioFormatParserTest extends SoundTransformTest { 12 | 13 | @Test 14 | public void testAudioFormatToIsi () { 15 | final StreamInfo audioFormat = new StreamInfo (2, 0, 2, 44100.0f, false, true, null); 16 | final Object isi2 = $.select (AudioFormatParser.class).audioFormatfromStreamInfo (audioFormat); 17 | org.junit.Assert.assertNotSame (null, isi2); 18 | } 19 | 20 | @Test 21 | public void testCDFormat () throws SoundTransformException { 22 | final StreamInfo isi = new StreamInfo (2, 0, 2, 44100.0f, false, true, null); 23 | final Object audioFormat = $.select (AudioFormatParser.class).audioFormatfromStreamInfo (isi); 24 | final FormatInfo fi = $.select (AudioFormatParser.class).fromAudioFormat (audioFormat, 0); 25 | org.junit.Assert.assertEquals (audioFormat.toString (), isi.toString ()); 26 | org.junit.Assert.assertEquals (audioFormat.toString (), fi.toString ()); 27 | } 28 | 29 | @Test 30 | public void testIsiToAudioFormat () { 31 | final StreamInfo isi = new StreamInfo (2, 0, 2, 44100.0f, false, true, null); 32 | final Object audioFormat = $.select (AudioFormatParser.class).audioFormatfromStreamInfo (isi); 33 | org.junit.Assert.assertEquals (audioFormat.toString (), isi.toString ()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/BlackBoxAndroidTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.mockito.Mockito; 6 | import org.toilelibre.libe.soundtransform.actions.notes.ImportAPackIntoTheLibrary; 7 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformAndroidTest; 8 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | import org.toilelibre.libe.soundtransform.model.library.Library; 11 | import org.toilelibre.libe.soundtransform.model.library.pack.Pack; 12 | 13 | import android.content.Context; 14 | import android.content.res.Resources; 15 | 16 | public class BlackBoxAndroidTest extends SoundTransformAndroidTest { 17 | 18 | static final class FakeR { 19 | public static final class attr { 20 | } 21 | 22 | public static final class raw { 23 | public static int gpiano6 = 0x7f020003; 24 | } 25 | } 26 | 27 | @Test 28 | public void importAndroidPack () throws SoundTransformException { 29 | //given 30 | Context fakeContext = Mockito.mock (Context.class); 31 | Resources fakeResources = Mockito.mock (Resources.class); 32 | Mockito.when (fakeContext.getResources ()).thenReturn (fakeResources); 33 | Mockito.when (fakeResources.openRawResource(1)).thenReturn ( 34 | Thread.currentThread ().getContextClassLoader ().getResourceAsStream ("smallpack.json")); 35 | Mockito.when (fakeResources.openRawResource (FakeR.raw.gpiano6)).thenReturn ( 36 | Thread.currentThread ().getContextClassLoader ().getResourceAsStream ("gpiano6.wav")); 37 | ImportAPackIntoTheLibrary importAPackAction = new ImportAPackIntoTheLibrary (); 38 | 39 | //when 40 | importAPackAction.importAPack ("pack1", fakeContext, FakeR.raw.class, 1); 41 | 42 | //then 43 | Pack pack1 = $.select (Library.class).getPack ("pack1"); 44 | Assert.assertTrue (pack1.size () == 1); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/ByteArrayTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.junit.Test; 6 | import org.toilelibre.libe.soundtransform.infrastructure.service.observer.Slf4jObserver; 7 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 8 | 9 | public class ByteArrayTest extends SoundTransformTest { 10 | 11 | byte [] array1 = { 42, -127, 23, 0 }; 12 | 13 | int byteArrayToInt (final byte [] bytes) { 14 | return bytes [3] << 24 | (bytes [2] & 0xFF) << 16 | (bytes [1] & 0xFF) << 8 | bytes [0] & 0xFF; 15 | } 16 | 17 | byte [] intToByteArray (final int n) { 18 | final byte [] b = new byte [4]; 19 | for (int i = 0 ; i < b.length ; i++) { 20 | b [i] = (byte) (n >> i * 8); 21 | } 22 | return b; 23 | } 24 | 25 | @Test 26 | public void test1 () { 27 | int i = this.byteArrayToInt (this.array1); 28 | i -= 320; 29 | final byte [] array2 = this.intToByteArray (i); 30 | new Slf4jObserver ().notify (Arrays.toString (this.array1)); 31 | new Slf4jObserver ().notify ("" + i); 32 | new Slf4jObserver ().notify (Arrays.toString (array2)); 33 | } 34 | 35 | @Test 36 | public void testEquals () { 37 | final int i = this.byteArrayToInt (this.array1); 38 | final byte [] array2 = this.intToByteArray (i); 39 | new Slf4jObserver ().notify (Arrays.toString (this.array1)); 40 | new Slf4jObserver ().notify ("" + i); 41 | new Slf4jObserver ().notify (Arrays.toString (array2)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/EqualizerTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms.EqualizerSoundTransform; 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.observer.Slf4jObserver; 6 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 7 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 9 | 10 | public class EqualizerTest extends SoundTransformTest { 11 | 12 | @Test 13 | public void test () { 14 | final long [] testarray = new long [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; 15 | final Channel testsound = new Channel (testarray, new FormatInfo (1, testarray.length), 1); 16 | final EqualizerSoundTransform est = new EqualizerSoundTransform (new double [] { 0, 4, 8 }, new double [] { 1, 1, 1 }); 17 | final Channel resultsound = est.transform (testsound); 18 | new Slf4jObserver ().notify (resultsound.viewSamplesArray ()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/FloatArrayCompressTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 5 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 6 | import org.toilelibre.libe.soundtransform.model.freqs.CompressFrequenciesProcessor; 7 | 8 | public class FloatArrayCompressTest extends SoundTransformTest { 9 | 10 | @Test 11 | public void shrink () { 12 | final float [] array = { 0, 1, 2, 3, 4, 5, 6 }; 13 | org.junit.Assert.assertArrayEquals (new float [] { 0, 2, 4, 6 }, $.select (CompressFrequenciesProcessor.class).compress (array, 2f), 0); 14 | } 15 | 16 | @Test 17 | public void stretch () { 18 | final float [] array = { 0, 1, 2, 3, 4, 5, 6 }; 19 | org.junit.Assert.assertArrayEquals (new float [] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6 }, $.select (CompressFrequenciesProcessor.class).compress (array, 0.5f), 0); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/FormatInfoTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 6 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 7 | 8 | public class FormatInfoTest { 9 | 10 | @Test 11 | public void formatInfoEquals () { 12 | final FormatInfo fi1 = new FormatInfo (2, 44100); 13 | final FormatInfo fi2 = new FormatInfo (2, 44100); 14 | Assert.assertTrue (fi1.sameFormatAs (fi2)); 15 | } 16 | 17 | @Test 18 | public void formatInfoEqualsStreamInfo () { 19 | final FormatInfo fi1 = new FormatInfo (2, 44100); 20 | final FormatInfo fi2 = new StreamInfo (2, 700000, 2, 44100, false, true, "Fenomenon - The B Minor Suite"); 21 | Assert.assertTrue (fi1.sameFormatAs (fi2)); 22 | } 23 | 24 | @Test 25 | public void formatInfoDifferentSampleRate () { 26 | final FormatInfo fi1 = new FormatInfo (2, 44100); 27 | final FormatInfo fi2 = new FormatInfo (2, 48000); 28 | Assert.assertFalse (fi1.sameFormatAs (fi2)); 29 | } 30 | 31 | @Test 32 | public void formatInfoDifferentSampleSize () { 33 | final FormatInfo fi1 = new FormatInfo (2, 44100); 34 | final FormatInfo fi2 = new FormatInfo (1, 44100); 35 | Assert.assertFalse (fi1.sameFormatAs (fi2)); 36 | } 37 | 38 | @Test 39 | public void formatInfoDifferentBoth () { 40 | final FormatInfo fi1 = new FormatInfo (2, 44100); 41 | final FormatInfo fi2 = new FormatInfo (1, 8000); 42 | Assert.assertFalse (fi1.sameFormatAs (fi2)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/Mp3Test.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import java.io.File; 4 | 5 | import org.junit.Test; 6 | import org.toilelibre.libe.soundtransform.actions.fluent.FluentClient; 7 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.transform.NoOpSoundTransform; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | 11 | public class Mp3Test extends SoundTransformTest { 12 | 13 | private final ClassLoader classLoader = Thread.currentThread ().getContextClassLoader (); 14 | private final File mp3input = new File (this.classLoader.getResource ("mp3test.mp3").getFile ()); 15 | 16 | private final File output = new File (new File (this.classLoader.getResource ("mp3test.mp3").getFile ()).getParent () + "/after.wav"); 17 | 18 | @Test 19 | public void testNoOp () throws SoundTransformException { 20 | FluentClient.start ().withFile (this.mp3input).convertIntoSound ().apply (new NoOpSoundTransform ()).exportToFile (this.output); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/Pcm2FrameTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.InputStream; 5 | 6 | import org.apache.commons.math3.random.RandomDataGenerator; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | import org.toilelibre.libe.soundtransform.infrastructure.service.observer.Slf4jObserver; 10 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 11 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 12 | import org.toilelibre.libe.soundtransform.model.converted.sound.Sound; 13 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 14 | import org.toilelibre.libe.soundtransform.model.inputstream.StreamInfo; 15 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.FrameProcessor; 16 | import org.toilelibre.libe.soundtransform.model.inputstream.readsound.InputStreamToSoundService; 17 | import org.toilelibre.libe.soundtransform.model.logging.LogEvent.LogLevel; 18 | 19 | public class Pcm2FrameTest extends SoundTransformTest { 20 | 21 | @Test 22 | public void testReversibleData () throws SoundTransformException { 23 | final RandomDataGenerator rdg = new RandomDataGenerator (); 24 | final byte [] data = new byte [256]; 25 | for (int i = 0 ; i < data.length ; i++) { 26 | data [i] = (byte) rdg.nextInt (Byte.MIN_VALUE, Byte.MAX_VALUE); 27 | } 28 | final InputStreamToSoundService ts = (InputStreamToSoundService) $.select (InputStreamToSoundService.class).setObservers (new Slf4jObserver (LogLevel.WARN)); 29 | final InputStream bais = new ByteArrayInputStream (data); 30 | final StreamInfo streamInfo = new StreamInfo (2, data.length / 4, 2, 44100.0f, false, true, null); 31 | final Sound sound = ts.fromInputStream (bais, streamInfo); 32 | 33 | final byte [] out = $.select (FrameProcessor.class).framesToByteArray (sound.getChannels (), streamInfo); 34 | Assert.assertArrayEquals (data, out); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/SlowdownTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms.SlowdownSoundTransform; 5 | import org.toilelibre.libe.soundtransform.infrastructure.service.observer.Slf4jObserver; 6 | import org.toilelibre.libe.soundtransform.ioc.SoundTransformTest; 7 | import org.toilelibre.libe.soundtransform.model.converted.FormatInfo; 8 | import org.toilelibre.libe.soundtransform.model.converted.sound.Channel; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | 11 | public class SlowdownTest extends SoundTransformTest { 12 | 13 | @Test 14 | public void test () throws SoundTransformException { 15 | final long [] testarray = new long [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; 16 | final Channel testsound = new Channel (testarray, new FormatInfo (1, testarray.length), 1); 17 | final SlowdownSoundTransform est = new SlowdownSoundTransform (2, 2, 4); 18 | final Channel resultsound = est.transform (testsound); 19 | new Slf4jObserver ().notify (resultsound.viewSamplesArray ()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/TestR.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | public final class TestR { 4 | public static final class attr { 5 | } 6 | 7 | public static final class raw { 8 | public static int badidpack = 0x7f020003; 9 | } 10 | } -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/WrongPackageAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.infrastructure.service.appender.AppenderAccessor; 5 | import org.toilelibre.libe.soundtransform.ioc.RootModuleWithoutAccessor; 6 | 7 | import se.jbee.inject.DIRuntimeException; 8 | 9 | public class WrongPackageAccessorTest { 10 | 11 | static class TestAccessor extends RootModuleWithoutAccessor { 12 | 13 | @Override 14 | protected void declare () { 15 | } 16 | } 17 | 18 | @Test (expected = DIRuntimeException.class) 19 | public void testOverride () { 20 | new AppenderAccessor () { 21 | 22 | @Override 23 | protected void declare () { 24 | 25 | } 26 | }; 27 | } 28 | 29 | @Test (expected = DIRuntimeException.class) 30 | public void testWrongPackage () { 31 | new TestAccessor (); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/WriteInputStreamToByteArrayTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.mockito.Matchers; 9 | import org.mockito.Mockito; 10 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 11 | 12 | public class WriteInputStreamToByteArrayTest { 13 | 14 | @Test (expected = SoundTransformException.class) 15 | public void errorWhileReadingStream () throws SoundTransformException { 16 | try { 17 | final WriteInputStreamToByteArray writer = new WriteInputStreamToByteArray (); 18 | final InputStream failingInputStream = Mockito.mock (InputStream.class); 19 | try { 20 | Mockito.when (failingInputStream.read (Matchers.any (byte [].class), Matchers.any (int.class), Matchers.any (int.class))).thenThrow (new IOException ("Forced failure")); 21 | } catch (final IOException e) { 22 | throw new RuntimeException (e); 23 | } 24 | writer.convertToByteArray (failingInputStream); 25 | } catch (final SoundTransformException ste) { 26 | Assert.assertEquals (ste.getErrorCode (), WriteInputStreamToByteArray.WriteInputStreamToByteArrayErrorCode.ERROR_WHILE_READING_STREAM); 27 | throw ste; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/android/AndroidFileToWavFileConverterTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.android; 2 | 3 | import java.io.File; 4 | 5 | import org.junit.Test; 6 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 7 | 8 | public class AndroidFileToWavFileConverterTest { 9 | 10 | @Test 11 | public void oggConvertToWav () throws SoundTransformException { 12 | new AndroidAudioFileHelper ().getUnknownInputStreamFromFile (new File (Thread.currentThread ().getContextClassLoader ().getResource ("raw/short.ogg").getFile ())); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/infrastructure/service/audioformat/javax/WavAudioFormatParserTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.audioformat.javax; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 6 | import org.toilelibre.libe.soundtransform.model.inputstream.format.AudioFormatParser; 7 | 8 | public class WavAudioFormatParserTest { 9 | 10 | @Test 11 | public void wrongTypeTest () throws SoundTransformException { 12 | try { 13 | new WavAudioFormatParser ().fromAudioFormat (new Object (), 0); 14 | Assert.fail ("Should have failed with read error"); 15 | } catch (final SoundTransformException ste) { 16 | Assert.assertEquals (ste.getErrorCode (), AudioFormatParser.AudioFormatParserErrorCode.READ_ERROR); 17 | } 18 | } 19 | 20 | @Test 21 | public void notASoundFileTest () throws SoundTransformException { 22 | try { 23 | new WavAudioFormatParser ().getStreamInfo (Thread.currentThread ().getContextClassLoader ().getResourceAsStream ("defaultpack.json")); 24 | Assert.fail ("Should have failed with read error"); 25 | } catch (final SoundTransformException ste) { 26 | Assert.assertEquals (ste.getErrorCode (), AudioFormatParser.AudioFormatParserErrorCode.WRONG_TYPE); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/infrastructure/service/sound2note/MagnitudeADSRHelperTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.infrastructure.service.sound2note; 2 | 3 | import org.junit.Test; 4 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 5 | 6 | public class MagnitudeADSRHelperTest { 7 | 8 | @Test 9 | public void decayWithoutException () throws SoundTransformException { 10 | new MagnitudeADSRHelper ().findDecay (new double [] { 1, 7, 15, 45, 80, 75, 76, 77, 78, 80 }, 5); 11 | } 12 | 13 | @Test 14 | public void sustainWithoutException () throws SoundTransformException { 15 | new MagnitudeADSRHelper ().findSustain (new double [] { 1, 7, 15, 45, 80, 79, 78, 77, 76, 75 }, 4); 16 | } 17 | 18 | @Test 19 | public void releaseWithoutException () throws SoundTransformException { 20 | new MagnitudeADSRHelper ().findRelease (new double [] { 1, 7, 15, 45, 80, 84, 95, 96, 97, 99 }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/ioc/CorrectPackageAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import org.junit.Test; 4 | 5 | public class CorrectPackageAccessorTest { 6 | 7 | static class TestAccessor extends RootModuleWithoutAccessor { 8 | 9 | @Override 10 | protected void declare () { 11 | } 12 | } 13 | 14 | @Test 15 | public void testCorrectPackage () { 16 | new TestAccessor (); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/ioc/SoundTransformAndroidTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import org.junit.BeforeClass; 4 | import org.toilelibre.libe.soundtransform.ioc.android.AndroidRootModule; 5 | 6 | import se.jbee.inject.bootstrap.Bootstrap; 7 | 8 | public class SoundTransformAndroidTest { 9 | 10 | @BeforeClass 11 | public static void setUp () { 12 | ApplicationInjector.injector = Bootstrap.injector (AndroidRootModule.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/ioc/SoundTransformTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.ioc; 2 | 3 | import org.junit.BeforeClass; 4 | import org.toilelibre.libe.soundtransform.ioc.javax.JavaXRootModule; 5 | 6 | import se.jbee.inject.bootstrap.Bootstrap; 7 | 8 | public class SoundTransformTest { 9 | 10 | @BeforeClass 11 | public static void setUp () { 12 | ApplicationInjector.injector = Bootstrap.injector (JavaXRootModule.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/toilelibre/libe/soundtransform/model/library/pack/DefaultAddNoteServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.toilelibre.libe.soundtransform.model.library.pack; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.UnsupportedEncodingException; 5 | 6 | import org.junit.Test; 7 | import org.toilelibre.libe.soundtransform.ioc.ApplicationInjector.$; 8 | import org.toilelibre.libe.soundtransform.model.exception.ErrorCode; 9 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException; 10 | import org.toilelibre.libe.soundtransform.model.exception.SoundTransformRuntimeException; 11 | import org.toilelibre.libe.soundtransform.model.library.pack.note.SimpleNoteInfo; 12 | 13 | public class DefaultAddNoteServiceTest { 14 | 15 | @Test (expected = SoundTransformException.class) 16 | public void addNoteWithInvalidInputStream () throws SoundTransformException, UnsupportedEncodingException { 17 | $.select (AddNoteService.class).addNote (new Range (), new SimpleNoteInfo (""), new ByteArrayInputStream ("dfsqfdsqfdsqdfdfqsqsdf".getBytes ("UTF-8"))); 18 | } 19 | 20 | @Test (expected = SoundTransformException.class) 21 | public void addNoteWithValidAbsoluteFile () throws SoundTransformException, UnsupportedEncodingException { 22 | $.select (AddNoteService.class).addNote (new Range (), new SimpleNoteInfo ("/dev/null")); 23 | if (System.getProperty("os.name").startsWith("Windows")) { 24 | throw new SoundTransformException(AddNoteService.AddNoteErrorCode.NOT_SUPPORTED, 25 | new UnsupportedOperationException("dev null does not exist")); 26 | } 27 | } 28 | 29 | @Test 30 | public void addNoteWithInvalidRelativeFile () throws SoundTransformException, UnsupportedEncodingException { 31 | $.select (AddNoteService.class).addNote (new Range (), new SimpleNoteInfo ("unknownfile.txt")); 32 | } 33 | 34 | @Test (expected = SoundTransformException.class) 35 | public void addNoteWithValidRelativeFile () throws SoundTransformException, UnsupportedEncodingException { 36 | $.select (AddNoteService.class).addNote (new Range (), new SimpleNoteInfo ("pom.xml")); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/before.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/test/resources/before.wav -------------------------------------------------------------------------------- /src/test/resources/mp3test.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/test/resources/mp3test.mp3 -------------------------------------------------------------------------------- /src/test/resources/notamp3file.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/test/resources/notamp3file.mp3 -------------------------------------------------------------------------------- /src/test/resources/raw/badidpack.json: -------------------------------------------------------------------------------- 1 | { 2 | "notaninstrument": [ 3 | { 4 | "frequency": 110.0, 5 | "name": "notafile", 6 | "attack": 0, 7 | "decay": 300, 8 | "sustain": 500, 9 | "release": 14732 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/test/resources/raw/short.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libetl/soundtransform/b46b4dada206dd24e87664d84d2303819c383add/src/test/resources/raw/short.ogg -------------------------------------------------------------------------------- /src/test/resources/smallpack.json: -------------------------------------------------------------------------------- 1 | { 2 | "g-piano": [ 3 | { 4 | "frequency": 97.75, 5 | "name": "gpiano6", 6 | "attack": 0, 7 | "decay": 400, 8 | "sustain": 400, 9 | "release": 14700 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/test/resources/wrongtechnicalinstrument.json: -------------------------------------------------------------------------------- 1 | { 2 | "org.toilelibre.libe.soundtransform.model.library.note.UnknownNote" : [] 3 | } 4 | --------------------------------------------------------------------------------