mirror of
https://github.com/dj0abr/SSB_HighSpeed_Modem.git
synced 2026-06-03 06:24:51 -04:00
update
This commit is contained in:
@@ -200,12 +200,13 @@ int io_fifo_freespace(int pipenum);
|
||||
// returns number of used elements (audio 16 bit short values)
|
||||
int io_fifo_usedspace(int pipenum);
|
||||
|
||||
// like before, but returns a number between 0 and 100 %
|
||||
int io_fifo_usedpercent(int pipenum);
|
||||
|
||||
// clear the fifo
|
||||
void io_fifo_clear(int pipenum);
|
||||
|
||||
// check if a playbackdevice is currently playing
|
||||
int isPlaying(int id);
|
||||
|
||||
|
||||
// -------- functions for internal use only --------
|
||||
|
||||
@@ -222,6 +223,7 @@ typedef struct _DEVLIST_ {
|
||||
int requested_samprate = 0; // sample rate requested by caller
|
||||
int real_samprate = 0; // real sample rate of the device
|
||||
int working = 0; // 0=not running, 1=initialized and working
|
||||
int audio_playing = 0; // audio is currently playing, or not
|
||||
#ifdef WIN32 // Windows using portaudio
|
||||
int devnum = -1; // port audio device number
|
||||
PaStreamParameters inputParameters;
|
||||
@@ -262,7 +264,7 @@ void close_playback_stream(int idx);
|
||||
|
||||
extern DEVLIST devlist[MAXDEVICES];
|
||||
extern int devanz;
|
||||
extern int keeprunning;
|
||||
extern int keepcallbacksrunning;
|
||||
|
||||
#ifndef WIN32 // Linux
|
||||
int kmaudio_init_linux();
|
||||
|
||||
@@ -150,7 +150,7 @@ int recordCallback( const void* inputBuffer,
|
||||
(void)timeInfo;
|
||||
(void)statusFlags;
|
||||
|
||||
if(keeprunning == 1)
|
||||
if(keepcallbacksrunning == 1)
|
||||
return paContinue;
|
||||
|
||||
return paComplete;
|
||||
|
||||
@@ -66,7 +66,7 @@ void read_callback(struct SoundIoInStream* instream, int frame_count_min, int fr
|
||||
struct SoundIoChannelArea* areas;
|
||||
// samples are in areas.ptr
|
||||
int frames_left = frame_count_max; // take all
|
||||
while (keeprunning)
|
||||
while (keepcallbacksrunning)
|
||||
{
|
||||
int frame_count = frames_left;
|
||||
if ((err = soundio_instream_begin_read(instream, &areas, &frame_count)))
|
||||
|
||||
@@ -233,7 +233,7 @@ int io_fifo_elems_avail(int pipenum)
|
||||
elems = (io_wridx[pipenum] + AUDIO_FIFOFLEN - io_rdidx[pipenum]) % AUDIO_FIFOFLEN;
|
||||
UNLOCK(pipenum);
|
||||
|
||||
elems -= 10;
|
||||
elems -= 10; // give some reserve
|
||||
return elems;
|
||||
}
|
||||
|
||||
@@ -241,12 +241,3 @@ int io_fifo_usedspace(int pipenum)
|
||||
{
|
||||
return AUDIO_FIFOFLEN - io_fifo_freespace(pipenum);
|
||||
}
|
||||
|
||||
int io_fifo_usedpercent(int pipenum)
|
||||
{
|
||||
int used = AUDIO_FIFOFLEN - io_fifo_freespace(pipenum);
|
||||
int percent = (used * 100) / AUDIO_FIFOFLEN;
|
||||
//printf("idx:%d used:%d size:%d percent:%d\n", pipenum, used, AUDIO_FIFOFLEN, percent);
|
||||
return percent;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
void kmaudio_close();
|
||||
|
||||
//int keeprunning = 1; // to stop callbacks at program end
|
||||
int keepcallbacksrunning = 1; // to stop callbacks at program end
|
||||
|
||||
int kmaudio_init()
|
||||
{
|
||||
@@ -43,7 +43,7 @@ int kmaudio_init()
|
||||
|
||||
printf("libkmaudio_init\n");
|
||||
|
||||
keeprunning = 1;
|
||||
keepcallbacksrunning = 1;
|
||||
init_pipes(); // init fifo
|
||||
init_maxarray(); // init array for maxlevel measurement
|
||||
|
||||
@@ -86,7 +86,7 @@ void kmaudio_close()
|
||||
#else
|
||||
kmaudio_close_linux();
|
||||
#endif
|
||||
keeprunning = 0;
|
||||
keepcallbacksrunning = 0;
|
||||
}
|
||||
/*
|
||||
// diagonstic routines for development
|
||||
|
||||
@@ -123,6 +123,11 @@ void getMax(int id, float fv)
|
||||
farridx[id] = 0;
|
||||
}
|
||||
|
||||
int isPlaying(int id)
|
||||
{
|
||||
return devlist[id].audio_playing;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the max level (within 1 second) of this stream in % (0..100)
|
||||
* if the level >= 100 the signal will get clipped and distorted
|
||||
|
||||
@@ -142,6 +142,7 @@ int playCallback( const void* inputBuffer,
|
||||
|
||||
//measure_speed_bps(framesPerBuffer);
|
||||
|
||||
/* das hier ging
|
||||
int16_t f[FRAMES_PER_BUFFER];
|
||||
memset(f, 0, sizeof(int16_t) * FRAMES_PER_BUFFER);
|
||||
unsigned int num = io_read_fifo_num_short(devidx, f, framesPerBuffer);
|
||||
@@ -150,6 +151,23 @@ int playCallback( const void* inputBuffer,
|
||||
//printf("got %d from fifo, requested %d\n", num, framesPerBuffer);
|
||||
}
|
||||
int av = io_fifo_elems_avail(devidx);
|
||||
das nächste ist neu
|
||||
*/
|
||||
|
||||
int16_t f[FRAMES_PER_BUFFER];
|
||||
// if fifo does not have enough data, just send 0.. (silence)
|
||||
// this gives the fifo a chance to fill up a bit
|
||||
memset(f, 0, sizeof(int16_t) * FRAMES_PER_BUFFER);
|
||||
if ((unsigned long)io_fifo_elems_avail(devidx) >= framesPerBuffer)
|
||||
{
|
||||
io_read_fifo_num_short(devidx, f, framesPerBuffer);
|
||||
devlist[devidx].audio_playing = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing to send
|
||||
devlist[devidx].audio_playing = 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < framesPerBuffer; i++)
|
||||
{
|
||||
@@ -166,7 +184,7 @@ int playCallback( const void* inputBuffer,
|
||||
(void)timeInfo;
|
||||
(void)statusFlags;
|
||||
|
||||
if (keeprunning == 1)
|
||||
if (keepcallbacksrunning == 1)
|
||||
return paContinue;
|
||||
|
||||
return paComplete;
|
||||
|
||||
@@ -85,12 +85,20 @@ static void write_callback(struct SoundIoOutStream* outstream, int frame_count_m
|
||||
}
|
||||
|
||||
float f[10000];
|
||||
// if fifo does not have enough data, just send 0.. (silence)
|
||||
// this gives the fifo a chance to fill up a bit
|
||||
memset(f, 0, sizeof(float) * frame_count);
|
||||
if (io_fifo_elems_avail(idx) >= frame_count)
|
||||
{
|
||||
// if fifo does not have enough data, don't take any
|
||||
// this gives the fifo a chance to fill up a bit
|
||||
io_read_fifo_num(idx, f, frame_count);
|
||||
//if (devlist[idx].audio_playing == 0) printf("NOW PLAYING\n");
|
||||
devlist[idx].audio_playing = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing to send
|
||||
//if (devlist[idx].audio_playing == 1) printf("STOPS playing\n");
|
||||
devlist[idx].audio_playing = 0;
|
||||
}
|
||||
|
||||
//measure_speed_bps(frame_count);
|
||||
@@ -132,8 +140,6 @@ static void write_callback(struct SoundIoOutStream* outstream, int frame_count_m
|
||||
|
||||
void underflow_callback(struct SoundIoOutStream* outstream)
|
||||
{
|
||||
static int count = 0;
|
||||
printf("underflow %d\n", count++);
|
||||
}
|
||||
|
||||
void close_playback_stream(int idx)
|
||||
@@ -148,7 +154,7 @@ void close_playback_stream(int idx)
|
||||
int kmaudio_startPlayback(char* devname, int samprate)
|
||||
{
|
||||
printf("Start request for PB stream:%s\n", devname);
|
||||
|
||||
|
||||
if (devname == NULL || strlen(devname) < 3) // no devices defined yet
|
||||
{
|
||||
printf("no PB devices specified\n");
|
||||
@@ -157,10 +163,11 @@ int kmaudio_startPlayback(char* devname, int samprate)
|
||||
|
||||
int idx = 0; // index into devlist
|
||||
char* pbdevid = getDevID(devname, 1, &idx);
|
||||
printf("idx:%d\n", idx);
|
||||
if (pbdevid == NULL) return -1;
|
||||
|
||||
close_playback_stream(idx);
|
||||
|
||||
|
||||
printf("Starting PB stream:%s [%d]\n", devname, idx);
|
||||
|
||||
io_fifo_clear(idx);
|
||||
@@ -199,7 +206,7 @@ int kmaudio_startPlayback(char* devname, int samprate)
|
||||
printf("soundio_outstream_create: out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
devlist[idx].requested_samprate = samprate;
|
||||
if (getRealSamprate(idx) == -1)
|
||||
{
|
||||
@@ -209,7 +216,7 @@ int kmaudio_startPlayback(char* devname, int samprate)
|
||||
|
||||
if (devlist[idx].requested_samprate != devlist[idx].real_samprate)
|
||||
resampler_create(idx);
|
||||
|
||||
|
||||
devlist[idx].outstream->format = SoundIoFormatFloat32NE;
|
||||
devlist[idx].outstream->sample_rate = devlist[idx].real_samprate;
|
||||
devlist[idx].outstream->software_latency = 0.1f;
|
||||
@@ -227,12 +234,13 @@ int kmaudio_startPlayback(char* devname, int samprate)
|
||||
printf("unable to start output device: %s", soundio_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("selected PLAYBACK device:\nname:%s\nid :%s\n", devname, pbdevid);
|
||||
printf("physical playback rate:%d, requested capture rate:%d\n", devlist[idx].real_samprate, devlist[idx].requested_samprate);
|
||||
printf("format: %s\n\n", soundio_format_string(devlist[idx].outstream->format));
|
||||
|
||||
|
||||
devlist[idx].working = 1;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,9 @@ typedef enum PaErrorCode
|
||||
paNoError = 0,
|
||||
|
||||
paNotInitialized = -10000,
|
||||
paUnanticipatedHostError,
|
||||
paInvalidChannelCount,
|
||||
paInvalidSampleRate,
|
||||
paUnanticipatedHostError, // -9999
|
||||
paInvalidChannelCount, // -9998
|
||||
paInvalidSampleRate, // -9997
|
||||
paInvalidDevice,
|
||||
paInvalidFlag,
|
||||
paSampleFormatNotSupported,
|
||||
|
||||
Reference in New Issue
Block a user