mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Version 4.2.1
This commit is contained in:
committed by
Stephen Sinclair
parent
a6381b9d38
commit
2cbce2d8bd
78
projects/examples/inetOut.cpp
Normal file
78
projects/examples/inetOut.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/******************************************/
|
||||
/*
|
||||
Example program to output N channels of audio
|
||||
data over a network socket connection.
|
||||
|
||||
by Gary P. Scavone, 2000
|
||||
|
||||
This program will load a specified WAV, SND, AIFF, STK RAW, or
|
||||
MAT-file formatted file. The output data format is set for signed
|
||||
16-bit integers. However, it is easy to change the InetWvOut
|
||||
setting to any of the other defined StkFormats. If using tcpIn, it
|
||||
will be necessary to change the expected data format there as well.
|
||||
|
||||
The class InetWvOut first attempts to establish a socket connection
|
||||
to a socket server running on port 2006. Therefore, this program
|
||||
needs to be started AFTER the streaming server.
|
||||
*/
|
||||
/******************************************/
|
||||
|
||||
#include "FileWvIn.h"
|
||||
#include "InetWvOut.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void usage(void) {
|
||||
// Error function in case of incorrect command-line
|
||||
// argument specifications.
|
||||
printf("\nuseage: inetOut file host <rate>\n");
|
||||
printf(" where file = the file to load,\n");
|
||||
printf(" host = the hostname where the receiving\n");
|
||||
printf(" application is running.\n");
|
||||
printf(" and rate = an optional playback rate for the file.\n");
|
||||
printf(" (default = 1.0, can be negative)\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Minimal command-line checking.
|
||||
if (argc < 3 || argc > 4) usage();
|
||||
|
||||
FileWvIn input;
|
||||
InetWvOut output;
|
||||
|
||||
// Load the file.
|
||||
try {
|
||||
input.openFile( (char *)argv[1] );
|
||||
}
|
||||
catch (StkError &) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Set the global STK sample rate to the file rate.
|
||||
Stk::setSampleRate( input.getFileRate() );
|
||||
|
||||
// Set input read rate.
|
||||
double rate = 1.0;
|
||||
if ( argc == 4 ) rate = atof(argv[3]);
|
||||
input.setRate( rate );
|
||||
|
||||
// Find out how many channels we have.
|
||||
int channels = input.getChannels();
|
||||
StkFrames frames( 4096, channels );
|
||||
|
||||
// Attempt to connect to the socket server.
|
||||
try {
|
||||
//output.connect( 2006, Socket::PROTO_UDP, (char *)argv[2], channels, Stk::STK_SINT16 );
|
||||
output.connect( 2006, Socket::PROTO_TCP, (char *)argv[2], channels, Stk::STK_SINT16 );
|
||||
}
|
||||
catch (StkError &) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Here's the runtime loop
|
||||
while ( !input.isFinished() )
|
||||
output.tickFrame( input.tickFrame( frames ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user