mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
#30 - WIP Streaming audio support. Adds Shoutcast V1 handler.
This commit is contained in:
70
src/record/wave/AudioPacketMonoWaveReader.java
Normal file
70
src/record/wave/AudioPacketMonoWaveReader.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package record.wave;
|
||||
|
||||
import audio.AudioPacket;
|
||||
import audio.IAudioPacketListener;
|
||||
import audio.metadata.AudioMetadata;
|
||||
import sample.Listener;
|
||||
import sample.real.RealBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class AudioPacketMonoWaveReader extends MonoWaveReader implements Listener<RealBuffer>
|
||||
{
|
||||
private AudioMetadata mMetadata = new AudioMetadata(0, false);
|
||||
|
||||
private IAudioPacketListener mListener;
|
||||
|
||||
/**
|
||||
* Reads wav files and converts the contents to AudioPackets.
|
||||
*
|
||||
* @param path of file to read containing 8kHz, 16-bit signed litte endian PCM audio
|
||||
* @param realTime causes the read() method to read and dispatch audio packets in real time. Note: when using
|
||||
* real time playback, the thread calling the read() method will sleep as needed to effect real-time playback,
|
||||
* therefore you should invoke read() on a separate thread if this will impact the calling thread.
|
||||
*
|
||||
* @throws IOException on any file IO errors
|
||||
*/
|
||||
public AudioPacketMonoWaveReader(Path path, boolean realTime) throws IOException
|
||||
{
|
||||
super(path, realTime);
|
||||
setListener(this);
|
||||
}
|
||||
|
||||
public void setMetadata(AudioMetadata metadata)
|
||||
{
|
||||
mMetadata = metadata;
|
||||
}
|
||||
|
||||
public void setListener(IAudioPacketListener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(RealBuffer realBuffer)
|
||||
{
|
||||
if(mListener != null)
|
||||
{
|
||||
mListener.getAudioPacketListener().receive(new AudioPacket(realBuffer.getSamples(), mMetadata));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user