Example #1
0
/**
 * Print the wave described by "sin_prop_ptr"
 */
void print_wave(SinePropPtr sin_prop_ptr)
{
	double samples_per_cycle;
	int number_of_samples;
	double cur_radian = 0.0;
	int i=0;
	unsigned result;
	
	samples_per_cycle = (double)(sin_prop_ptr->sample_rate) / (sin_prop_ptr->frequency);
	number_of_samples = (sin_prop_ptr->sample_rate) * (sin_prop_ptr->duration);
	
	/*Do the math to calculate the values for the described sine wave*/
	for(i=0; i<number_of_samples; i++)
	{
		result = (unsigned)((sin(cur_radian))*(sin_prop_ptr->amplitude/2) + 
													(sin_prop_ptr->amplitude/2));
		if(sin_prop_ptr->mono_or_stereo == STEREO)
		{
			/*Print out two channels of the same amplitude*/
			output_sample(stdout, result, sin_prop_ptr->bit_size);
		}
		output_sample(stdout, result, sin_prop_ptr->bit_size);
		cur_radian += 2*M_PI / (samples_per_cycle);
	}
	
	return;
}
Example #2
0
interrupt void c_int11()         	//interrupt service routine
{
   output_sample(AIC_buffer.samples);   	//output data
   AIC_buffer.samples= input_sample(); 	    //input data
   intflag = TRUE;
   return;
}
Example #3
0
interrupt void c_int11()         //interrupt service routine
{
   short sample_data;

   sample_data = input_sample(); //input data
   output_sample(sample_data);   //output data
   return;
}
Example #4
0
/**
 * Part D: Static
 * Output random data values according to the specified parameters to the standard output.
 * Each value will be between 0 and 2^(bit-size)-1
 *
 * Command Line Variables: static <bit-size> <number of samples> <sample rate>
 * Return Values: 0 - Success; 1 - Failure (error written to stderr)
 */
int main(int argc, char* argv[])
{
	int bit_size;
	int num_samples;
	int sample_rate;
	unsigned max_sample;
	int i;
	unsigned sample;
	
	if(argc != NUM_ARGS)
	{
		fprintf(stderr, "You must enter all 3 parameters");
		return 1;
	}
	
	/*Get the parameters*/
	bit_size = atoi(argv[1]);
	if((bit_size != 8) && (bit_size != 16) && (bit_size != 32))
	{
		fprintf(stderr, "The value for bit-size must be 8, 16, or 32\n");
		return 1;
	}
	
	num_samples = atoi(argv[2]);
	if(num_samples < 0 || num_samples >= INT_MAX)
	{
		fprintf(stderr, "The value for number of samples is not a legal positive integer.\n");
		return(1);
	}
	
	sample_rate = atoi(argv[3]);
	if(sample_rate < 0 || sample_rate >= INT_MAX)
	{
		fprintf(stderr, "The value for sample rate is not a legal positive integer.\n");
		return(1);
	}
	
	/*Print header info*/
	printf("Header\n");
	printf("FREQUENCY %d\n", sample_rate);
	printf("SAMPLE %d\n", num_samples);
	printf("CHANNELS MONO\n");
	printf("SAMPLEBITS %d\n", bit_size);
	printf("EndHeader\n");
	
	/*Print the "static" samples*/
	i=0;
	srand(time(NULL));
	max_sample = (unsigned)(pow(2, bit_size))-1;
	while(i<num_samples)
	{
		sample = rand() % max_sample;
		output_sample(stdout, sample, bit_size);
		i++;
	}
	
	return 0;
}
Example #5
0
File: mkwav.c Project: blucz/tvon
void write_pulse(int one_or_zero, int cycles, int freq) {
    short val = one_or_zero ? (short)0x7fff : (short)0x0;

    double time_seconds = (double)cycles / (double)freq;
    int cycles_at_sample_rate = (int)(time_seconds * SAMPLE_RATE);

    int i;
    printf("write %d samples of %d\n", cycles_at_sample_rate, val);
    for (i = 0; i < cycles_at_sample_rate; i++) {
        output_sample(val, val);
    }
}
Example #6
0
File: info.c Project: vtanakas/mame
void info_xml_creator::output_one_device(device_t &device, const char *devtag)
{
	bool has_speaker = FALSE, has_input = FALSE;
	// check if the device adds speakers to the system
	sound_interface_iterator snditer(device);
	if (snditer.first() != NULL)
		has_speaker = TRUE;
	// generate input list
	ioport_list portlist;
	std::string errors;
	device_iterator iptiter(device);
	for (device_t *dev = iptiter.first(); dev != NULL; dev = iptiter.next())
		portlist.append(*dev, errors);
	// check if the device adds player inputs (other than dsw and configs) to the system
	for (ioport_port *port = portlist.first(); port != NULL; port = port->next())
		for (ioport_field *field = port->first_field(); field != NULL; field = field->next())
			if (field->type() >= IPT_START1 && field->type() < IPT_UI_FIRST)
			{
				has_input = TRUE;
				break;
			}

	// start to output info
	fprintf(m_output, "\t<%s", emulator_info::get_xml_top());
	fprintf(m_output, " name=\"%s\"", xml_normalize_string(device.shortname()));
	std::string src(device.source());
	strreplace(src,"../", "");
	fprintf(m_output, " sourcefile=\"%s\"", xml_normalize_string(src.c_str()));
	fprintf(m_output, " isdevice=\"yes\"");
	fprintf(m_output, " runnable=\"no\"");
	output_sampleof();
	fprintf(m_output, ">\n");
	fprintf(m_output, "\t\t<description>%s</description>\n", xml_normalize_string(device.name()));

	output_rom(device);

	samples_device *samples = dynamic_cast<samples_device*>(&device);
	if (samples==NULL) output_sample(device); // ignore samples_device itself

	output_chips(device, devtag);
	output_display(device, devtag);
	if (has_speaker)
		output_sound(device);
	if (has_input)
		output_input(portlist);
	output_switches(portlist, devtag, IPT_DIPSWITCH, "dipswitch", "dipvalue");
	output_switches(portlist, devtag, IPT_CONFIG, "configuration", "confsetting");
	output_adjusters(portlist);
	output_images(device, devtag);
	output_slots(device, devtag);
	fprintf(m_output, "\t</%s>\n", emulator_info::get_xml_top());
}
Example #7
0
interrupt void c_int11() //interrupt service routine
{
int i, outval= 0;
short X = 0;
if(stabilizeOutput++ < STABILIZE_LEN) //delay start to Stabilize
{
r[0] = input_sample();
output_sample(0);
return;
}
if(encSeqNum < MAX_DATA_LENGTH) //modulate data sequence
{
outval = (int) sigAmp[encodeSeq[encSeqNum]]*phi_1[encSymbolVal++];
if(encSymbolVal>=N) {encSeqNum++; encSymbolVal=0; }
output_sample(outval);
}
else output_sample(0); //0 if MAX_DATA_LENGTH exceeded
r[rNum++] = (short) input_sample();//input signal
buffer[buflen++] = r[rNum - 1];
if(beginDemod) //demod received signal
{
if(decSeqNum<2 && rNum==N) { //account for delay in signal
decSeqNum ++; rNum = 0; }
if(rNum == N) //synchronize to symbol length
{
rNum = 0;
for(i=0; i<N; i++) //correlate with basis function
X += r[i]*phi_1[i];
decodeSeq[decSeqNum-2] = (X >= 0) ? 1: 0; //do detection
if(++decSeqNum == MAX_DATA_LENGTH+2) //print received sequence
{
for(i=0; i<decSeqNum-2; i++)
printf("Received Value: %d\n", decodeSeq[i]);
exit(0);
}
}
}
else { beginDemod = 1; rNum = 0; }
}
Example #8
0
// for communication/init using interrupt
void comm_intr() {

	// 0 since not polling
	poll=0;

   	// disable interrupts
	IRQ_globalDisable();

	// init DSP and codec
	c6713_dsk_init();

	// McBSP1 Xmit
	CODECEventId=MCBSP_getXmtEventId(DSK6713_AIC23_codecdatahandle);

	// do not need to point to vector table
	#ifndef using_bios
	//point to the IRQ vector table
	IRQ_setVecs(vectors);
	//since interrupt vector handles this
	#endif

	// map McBSP1 Xmit to INT11
  	IRQ_map(CODECEventId, 11);

 	// reset codec INT 11
  	IRQ_reset(CODECEventId);

  	// globally enable interrupts
  	IRQ_globalEnable();

	// enable NMI interrupt
  	IRQ_nmiEnable();

  	// enable CODEC eventXmit INT11
  	IRQ_enable(CODECEventId);

	// start McBSP interrupt outputting a sample
	output_sample(0);
}
Example #9
0
File: mkwav.c Project: blucz/tvon
int main() {
    output_file = fopen("output.wav", "wb");
    if (!output_file)
        die_perror("failed to open file");

    int samplerate    = SAMPLE_RATE;
    int channels      = 2;
    int bitspersample = 16;

    int datarate = samplerate * channels * (bitspersample / 8);
    int blockalign = channels * (bitspersample / 8);

    // write wav header
    output_write("RIFF", 4);
    long riff_len_pos = ftell(output_file);     // need to write 36+datalen to riff_len_pos
    write_le32(0);      
    output_write("WAVE", 4);
    output_write("fmt ", 4);
    write_le32(16);
    write_le16(1);
    write_le16(channels);
    write_le32(samplerate);
    write_le32(datarate);
    write_le16(blockalign);
    write_le16(bitspersample);
    output_write("data", 4);
    long wav_data_pos = ftell(output_file);     // need to write datalen to wav_data_pos
    write_le32(0);      

    int i;
    for (i = 0; i < 22050; i++) output_sample(0, 0);    // write 500ms of silence

    write_pulse(1, 4909, 1000000);         // command start
    write_pulse(0, 4320, 1000000);

    i = 0;
    unsigned code = 0xe0e040bf;
    for (i = 0; i < 32; i++) {
        int bit = (code >> (31 - i)) & 0x1;

        if (bit) {
            write_pulse(1, 818, 1000000);         // 1 bit
            write_pulse(0, 1425, 1000000);
        } else {
            write_pulse(1, 818, 1000000);         // 0 bit
            write_pulse(0, 325, 1000000);
        }
    }

    write_pulse(1, 717, 1000000);          // command stop
    write_pulse(0, 717, 1000000);

    for (i = 0; i < 22050; i++) output_sample(0, 0);    // write 500ms of silence

    fseek(output_file, riff_len_pos, SEEK_SET);
    write_le32(36 + datalen);

    fseek(output_file, wav_data_pos, SEEK_SET);
    write_le32(datalen);

    fclose(output_file);

    return 0;
}
Example #10
0
interrupt void c_int11() {  // Interrupt Service Routine
     if (index < N) {
         output_sample((int)io_buffer[index]);
        io_buffer[index++]=(float)input_left_sample();
    }
}
Example #11
0
interrupt void c_int11()
{
  output_sample(square_table[loopindex++]);
  if (loopindex >= LOOPLENGTH)
    loopindex = 0;
  return;										}
Example #12
0
void info_xml_creator::output_one()
{
	// no action if not a game
	const game_driver &driver = m_drivlist.driver();
	if (driver.flags & GAME_NO_STANDALONE)
		return;

	// allocate input ports
	machine_config &config = m_drivlist.config();
	ioport_list portlist;
	astring errors;
	device_iterator iter(config.root_device());
	for (device_t *device = iter.first(); device != NULL; device = iter.next())
		portlist.append(*device, errors);

	// print the header and the game name
	fprintf(m_output, "\t<%s",emulator_info::get_xml_top());
	fprintf(m_output, " name=\"%s\"", xml_normalize_string(driver.name));

	// strip away any path information from the source_file and output it
	const char *start = strrchr(driver.source_file, '/');
	if (start == NULL)
		start = strrchr(driver.source_file, '\\');
	if (start == NULL)
		start = driver.source_file - 1;
	fprintf(m_output, " sourcefile=\"%s\"", xml_normalize_string(start + 1));

	// append bios and runnable flags
	if (driver.flags & GAME_IS_BIOS_ROOT)
		fprintf(m_output, " isbios=\"yes\"");
	if (driver.flags & GAME_NO_STANDALONE)
		fprintf(m_output, " runnable=\"no\"");
	if (driver.flags & GAME_MECHANICAL)
		fprintf(m_output, " ismechanical=\"yes\"");

	// display clone information
	int clone_of = m_drivlist.find(driver.parent);
	if (clone_of != -1 && !(m_drivlist.driver(clone_of).flags & GAME_IS_BIOS_ROOT))
		fprintf(m_output, " cloneof=\"%s\"", xml_normalize_string(m_drivlist.driver(clone_of).name));
	if (clone_of != -1)
		fprintf(m_output, " romof=\"%s\"", xml_normalize_string(m_drivlist.driver(clone_of).name));

	// display sample information and close the game tag
	output_sampleof();
	fprintf(m_output, ">\n");

	// output game description
	if (driver.description != NULL)
		fprintf(m_output, "\t\t<description>%s</description>\n", xml_normalize_string(driver.description));

	// print the year only if is a number or another allowed character (? or +)
	if (driver.year != NULL && strspn(driver.year, "0123456789?+") == strlen(driver.year))
		fprintf(m_output, "\t\t<year>%s</year>\n", xml_normalize_string(driver.year));

	// print the manufacturer information
	if (driver.manufacturer != NULL)
		fprintf(m_output, "\t\t<manufacturer>%s</manufacturer>\n", xml_normalize_string(driver.manufacturer));

	// now print various additional information
	output_bios();
	output_rom(m_drivlist.config().root_device());
	output_device_roms();
	output_sample(m_drivlist.config().root_device());
	output_chips(m_drivlist.config().root_device(), "");
	output_display(m_drivlist.config().root_device(), "");
	output_sound(m_drivlist.config().root_device());
	output_input(portlist);
	output_switches(portlist, "", IPT_DIPSWITCH, "dipswitch", "dipvalue");
	output_switches(portlist, "", IPT_CONFIG, "configuration", "confsetting");
	output_ports(portlist);
	output_adjusters(portlist);
	output_driver();
	output_images(m_drivlist.config().root_device(), "");
	output_slots(m_drivlist.config().root_device(), "");
	output_software_list();
	output_ramoptions();

	// close the topmost tag
	fprintf(m_output, "\t</%s>\n",emulator_info::get_xml_top());
}
Example #13
0
interrupt void c_int11() {
	if (sample<LBUFF)
		output_sample(iobuffer[sample++]);
}