Программирование на синтезаторе Java

Я пытаюсь научиться создавать синтезатор с нуля, используя Java. Я пытался связать воедино некоторые учебные пособия и код, чтобы попытаться изучить основной рабочий продукт, но у меня нет звука. Я просто хочу иметь возможность генерировать звук, используя грех, пила и прямоугольные волны. Когда я запускаю программу, у меня нет звука. Я думаю, что мои проблемы в классе Main.java и классе SamplePlayer.java. Я получаю сообщение об ошибке в классе SamplePlayer.java, которое я опубликую в конце. Кто-нибудь знает, что я делаю неправильно или что нужно изменить, чтобы создать базовый звук?

У меня 6 классов:

  • Envelope.java (настраивает генератор конвертов ADSR)

  • Main.java (содержит основную функцию)

    public class Main
    {
        public static void main(String[] args) 
        {
        // Create an oscillator sample producer
        Oscillator osc = new Oscillator();
    
        // Set the frequency
        osc.setFrequency(500);
    
        // Set the waveashape
        //osc.setWaveshape(WAVESHAPE.SIN);
    
        // Create a sample player
        SamplePlayer player = new SamplePlayer();
    
        // Sets the player's sample provider
        player.setSampleProvider(osc);
    
        // Start the player
        player.startPlayer();
    
        // Delay so oscillator can be heard
        try
        {
            TimeUnit.SECONDS.sleep(4);  
        }
        catch(InterruptedException e)
        {
    
        }
    
        // Stop the player
        player.stopPlayer();
    }
    
    }
    
  • SamplePlayer.java (отвечает за сэмплирование волн и воспроизведение звука)

    import java.nio.ByteBuffer;
    
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.SourceDataLine;
    
    public class SamplePlayer extends Thread 
    {
    
        // AudioFormat parameters
        public  static final int     SAMPLE_RATE = 22050;
        private static final int     SAMPLE_SIZE = 16;
        private static final int     CHANNELS = 1;
        private static final boolean SIGNED = true;
        private static final boolean BIG_ENDIAN = true;
    
        // Chunk of audio processed at one time
        public static final int BUFFER_SIZE = 1000;
        public static final int SAMPLES_PER_BUFFER = BUFFER_SIZE / 2;
    
        public SamplePlayer() 
        {
    
            // Create the audio format we wish to use
            format = new AudioFormat(SAMPLE_RATE, SAMPLE_SIZE, CHANNELS, SIGNED, BIG_ENDIAN);
    
            // Create dataline info object describing line format
            info = new DataLine.Info(SourceDataLine.class, format);
        }
    
        public void run() 
        {
    
            done = false;
            int nBytesRead = 0;
    
            try 
            {
                // Get line to write data to
                auline = (SourceDataLine) AudioSystem.getLine(info);
                auline.open(format);
                auline.start();
    
                while ((nBytesRead != -1) && (! done)) 
                {
                    nBytesRead = getSamples(sampleData);
                    if (nBytesRead > 0) {
                        auline.write(sampleData, 0, nBytesRead);
                    }
                }
    
            } catch(Exception e) 
            {
                e.printStackTrace();                
            } finally {
                auline.drain();
                auline.close();                         
            }
        }       
    
        public void startPlayer() 
        {
            if (provider != null) 
            {
                start();    
            }
        }
    
        public void stopPlayer() 
        {
            done = true;
        }
    
        public void setSampleProvider(SampleProviderIntfc provider) 
        {
            this.provider = provider;
        }
        public int getSamples(byte [] samples)
        {
            return ByteBuffer.wrap(samples).getInt();
        }
    
        // Instance data
        private AudioFormat format;
        private DataLine.Info info;
        private SourceDataLine auline;
        private boolean done;
        private byte [] sampleData = new byte[BUFFER_SIZE];
        private SampleProviderIntfc provider;
    }
    
  • SampleProviderIntfc.java (имеет заглушку метода getSamples())

Ошибка, сгенерированная в SamplePlayer.java:

2015-11-12 00:37:22.215 java[892:2167212] Error loading /Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn:  dlopen(/Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn, 262): no suitable image found.  Did find:
    /Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn: mach-o, but wrong architecture
2015-11-12 00:37:22.215 java[892:2167212] Cannot find function pointer New_SHP_PlugIn for factory 834FC054-C1CC-11D6-BD01-00039315CD46 in CFBundle/CFPlugIn 0x7fd7abd29180 </Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin> (bundle, not loaded)
2015-11-12 00:37:22.253 java[892:2167212] 00:37:22.252 WARNING:  >compload> 472: Kickstart.component -- file://localhost/Library/Audio/Plug-Ins/Components/: trouble parsing Info.plist's AudioComponents, key (null); entry: <CFBasicHash 0x7fd7abc44cc0 [0x7fff73159390]>{type = mutable dict, count = 7,
entries =>
    2 : <CFString 0x7fff730e39f0 [0x7fff73159390]>{contents = "manufacturer"} = <CFString 0x7fd7abc4b9c0 [0x7fff73159390]>{contents = "CaNR"}
    7 : <CFString 0x7fff730e74b0 [0x7fff73159390]>{contents = "factoryFunction"} = <CFString 0x7fd7abc4b090 [0x7fff73159390]>{contents = "KickstartAUFactory"}
    8 : <CFString 0x7fd7abc4baa0 [0x7fff73159390]>{contents = "subtype"} = <CFString 0x7fd7abc4bae0 [0x7fff73159390]>{contents = "CNKS"}
    9 : <CFString 0x7fff7310b6f0 [0x7fff73159390]>{contents = "description"} = <CFString 0x7fd7abc4c180 [0x7fff73159390]>{contents = "Kickstart"}
    10 : <CFString 0x7fff7310a3d0 [0x7fff73159390]>{contents = "type"} = <CFString 0x7fd7abc4bbc0 [0x7fff73159390]>{contents = "kAudioUnitType_Effect"}
    11 : <CFString 0x7fff73095bb0 [0x7fff73159390]>{contents = "name"} = <CFString 0x7fd7abc4b990 [0x7fff73159390]>{contents = "Nicky Romero: Kickstart"}
    12 : <CFString 0x7fff73114370 [0x7fff73159390]>{contents = "version"} = <CFNumber 0x1000937 [0x7fff73159390]>{value = +65545, type = kCFNumberSInt64Type}
}
2015-11-12 00:37:22.256 java[892:2167212] 00:37:22.256 WARNING:  >compload> 472: Primer.component -- file://localhost/Library/Audio/Plug-Ins/Components/: trouble parsing Info.plist's AudioComponents, key (null); entry: <CFBasicHash 0x7fd7abc4b0f0 [0x7fff73159390]>{type = mutable dict, count = 7,
entries =>
    2 : <CFString 0x7fff730e39f0 [0x7fff73159390]>{contents = "manufacturer"} = <CFString 0x7fd7abc4b3e0 [0x7fff73159390]>{contents = "AudG"}
    7 : <CFString 0x7fff730e74b0 [0x7fff73159390]>{contents = "factoryFunction"} = <CFString 0x7fd7abc4b090 [0x7fff73159390]>{contents = "PrimerAUFactory"}
    8 : <CFString 0x7fd7abc4ac30 [0x7fff73159390]>{contents = "subtype"} = <CFString 0x7fd7abc4b990 [0x7fff73159390]>{contents = "agp"}
    9 : <CFString 0x7fff7310b6f0 [0x7fff73159390]>{contents = "description"} = <CFString 0x7fd7abc4af00 [0x7fff73159390]>{contents = "Primer"}
    10 : <CFString 0x7fff7310a3d0 [0x7fff73159390]>{contents = "type"} = <CFString 0x7fd7abc4c4c0 [0x7fff73159390]>{contents = "aumu"}
    11 : <CFString 0x7fff73095bb0 [0x7fff73159390]>{contents = "name"} = <CFString 0x7fd7abc4a1a0 [0x7fff73159390]>{contents = "Audible Genius: Primer"}
    12 : <CFString 0x7fff73114370 [0x7fff73159390]>{contents = "version"} = <CFNumber 0x1010137 [0x7fff73159390]>{value = +65793, type = kCFNumberSInt64Type}
}

Эти ошибки генерируются в строках:

auline = (SourceDataLine) AudioSystem.getLine(info);
auline.open(format);

Любая помощь или шаг в правильном направлении будет принята с благодарностью. Спасибо!

0 ответов

Другие вопросы по тегам