Update Audacity's Nyquist interface for r331 (r3.16+)

This includes converting some types to int64_t to be
compatible with Nyquist's improved 64-bit support.
This commit is contained in:
Leland Lucius 2021-01-28 02:34:43 -06:00
parent edb00dd422
commit f24d42d510
4 changed files with 51 additions and 29 deletions

View File

@ -9,6 +9,7 @@
**********************************************************************/
/* system includes */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -74,7 +75,7 @@ LOCAL XLCONTEXT nyx_cntxt;
LOCAL int nyx_first_time = 1;
LOCAL LVAL nyx_obarray;
LOCAL FLOTYPE nyx_warp_stretch;
LOCAL long nyx_input_length = 0;
LOCAL int64_t nyx_input_length = 0;
LOCAL char *nyx_audio_name = NULL;
/* Suspension node */
@ -82,7 +83,7 @@ typedef struct nyx_susp_struct {
snd_susp_node susp; // Must be first
nyx_audio_callback callback;
void *userdata;
long len;
int64_t len;
int channel;
} nyx_susp_node, *nyx_susp_type;
@ -542,7 +543,7 @@ LOCAL void nyx_susp_fetch(nyx_susp_type susp, snd_list_type snd_list)
{
sample_block_type out;
sample_block_values_type out_ptr;
long n;
int64_t n;
int err;
falloc_sample_block(out, "nyx_susp_fetch");
@ -613,7 +614,7 @@ void nyx_set_audio_name(const char *name)
nyx_audio_name = strdup(name);
}
void nyx_set_audio_params(double rate, long len)
void nyx_set_audio_params(double rate, int64_t len)
{
LVAL flo;
LVAL con;
@ -651,7 +652,7 @@ void nyx_set_audio_params(double rate, long len)
void nyx_set_input_audio(nyx_audio_callback callback,
void *userdata,
int num_channels,
long len, double rate)
int64_t len, double rate)
{
LVAL val;
int ch;
@ -923,8 +924,8 @@ int nyx_get_audio(nyx_audio_callback callback, void *userdata)
{
float *buffer = NULL;
sound_type *snds = NULL;
long *totals = NULL;
long *lens = NULL;
int64_t *totals = NULL;
int64_t *lens = NULL;
sound_type snd;
int result = 0;
int num_channels;
@ -957,12 +958,12 @@ int nyx_get_audio(nyx_audio_callback callback, void *userdata)
goto finish;
}
totals = (long *) malloc(num_channels * sizeof(long));
totals = (int64_t *) malloc(num_channels * sizeof(int64_t));
if (totals == NULL) {
goto finish;
}
lens = (long *) malloc(num_channels * sizeof(long));
lens = (int64_t *) malloc(num_channels * sizeof(int64_t));
if (lens == NULL) {
goto finish;
}
@ -982,10 +983,10 @@ int nyx_get_audio(nyx_audio_callback callback, void *userdata)
LVAL val = getvalue(xlenter("LEN"));
if (val != s_unbound) {
if (ntype(val) == FLONUM) {
nyx_input_length = (long) getflonum(val);
nyx_input_length = (int64_t) getflonum(val);
}
else if (ntype(val) == FIXNUM) {
nyx_input_length = (long) getfixnum(val);
nyx_input_length = (int64_t) getfixnum(val);
}
}
}
@ -1005,7 +1006,7 @@ int nyx_get_audio(nyx_audio_callback callback, void *userdata)
while (result == 0) {
for (ch =0 ; ch < num_channels; ch++) {
sample_block_type block;
long cnt;
int cnt;
int i;
snd = snds[ch];
@ -1230,11 +1231,6 @@ void oserror(const char *msg)
errputstr(msg);
}
long osrand(long n)
{
return (((int) rand()) % n);
}
/* cd ..
open - open an ascii file */
FILE *osaopen(const char *name, const char *mode)
@ -1573,5 +1569,31 @@ void get_xlisp_path(char *p, long p_max)
strncpy(p, paths, p_max);
p[p_max-1] = 0;
}
/* xgetrealtime - get current time in seconds */
LVAL xgetrealtime()
{
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = (uint64_t) file_time.dwLowDateTime;
time += ((uint64_t) file_time.dwHighDateTime) << 32;
time -= EPOCH;
time /= 10000000L;
return cvflonum((double) time + system_time.wMilliseconds * 0.001);
}
#else
#include <sys/time.h>
/* xgetrealtime - get current time in seconds */
LVAL xgetrealtime(void)
{
struct timeval te;
gettimeofday(&te, NULL); // get current time
return cvflonum((double) te.tv_sec + (te.tv_usec * 1e-6));
}
#endif

View File

@ -35,8 +35,8 @@ extern "C"
/* should return return 0 for success, -1 for error */
typedef int (*nyx_audio_callback)(float *buffer,
int channel,
long start, long len,
long totlen,
int64_t start, int64_t len,
int64_t totlen,
void *userdata);
typedef void (*nyx_output_callback)(int c,
@ -56,12 +56,12 @@ extern "C"
void nyx_break();
void nyx_continue();
void nyx_set_audio_params(double rate, long len);
void nyx_set_audio_params(double rate, int64_t len);
void nyx_set_input_audio(nyx_audio_callback callback,
void *userdata,
int num_channels,
long len, double rate);
int64_t len, double rate);
char *nyx_get_audio_name();
void nyx_set_audio_name(const char *name);

View File

@ -2400,7 +2400,7 @@ bool NyquistEffect::ParseCommand(const wxString & cmd)
}
int NyquistEffect::StaticGetCallback(float *buffer, int channel,
long start, long len, long totlen,
int64_t start, int64_t len, int64_t totlen,
void *userdata)
{
NyquistEffect *This = (NyquistEffect *)userdata;
@ -2408,7 +2408,7 @@ int NyquistEffect::StaticGetCallback(float *buffer, int channel,
}
int NyquistEffect::GetCallback(float *buffer, int ch,
long start, long len, long WXUNUSED(totlen))
int64_t start, int64_t len, int64_t WXUNUSED(totlen))
{
if (mCurBuffer[ch].ptr()) {
if ((mCurStart[ch] + start) < mCurBufferStart[ch] ||
@ -2467,7 +2467,7 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
}
int NyquistEffect::StaticPutCallback(float *buffer, int channel,
long start, long len, long totlen,
int64_t start, int64_t len, int64_t totlen,
void *userdata)
{
NyquistEffect *This = (NyquistEffect *)userdata;
@ -2475,7 +2475,7 @@ int NyquistEffect::StaticPutCallback(float *buffer, int channel,
}
int NyquistEffect::PutCallback(float *buffer, int channel,
long start, long len, long totlen)
int64_t start, int64_t len, int64_t totlen)
{
// Don't let C++ exceptions propagate through the Nyquist library
return GuardedCall<int>( [&] {

View File

@ -145,18 +145,18 @@ private:
FileNames::FileTypes ParseFileTypes(const wxString & text);
static int StaticGetCallback(float *buffer, int channel,
long start, long len, long totlen,
int64_t start, int64_t len, int64_t totlen,
void *userdata);
static int StaticPutCallback(float *buffer, int channel,
long start, long len, long totlen,
int64_t start, int64_t len, int64_t totlen,
void *userdata);
static void StaticOutputCallback(int c, void *userdata);
static void StaticOSCallback(void *userdata);
int GetCallback(float *buffer, int channel,
long start, long len, long totlen);
int64_t start, int64_t len, int64_t totlen);
int PutCallback(float *buffer, int channel,
long start, long len, long totlen);
int64_t start, int64_t len, int64_t totlen);
void OutputCallback(int c);
void OSCallback();