├── .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 extends Serializable> 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.