static BYTE digiblaster_read(WORD addr) { if ((addr & 1) == 0) { return sound_read(digiblaster_sound_chip_offset, 0); } return sampler_get_sample(SAMPLER_CHANNEL_DEFAULT); }
/* * Play DSP from WAV file: */ int PlayDSP(DSPFILE *dfile, WAVFILE *wfile) { UInt32 byte_count = (UInt32) wfile->wavinfo.Samples; int bytes; int n; int byte_modulo; int total_bytes; //First determine how many bytes are required for each channel's sample: switch ( wfile->wavinfo.DataBits ) { case 8 : byte_count = 1; break; case 16 : byte_count = 2; break; default : printf("Cannot process %u bit samples\n", (unsigned)wfile->wavinfo.DataBits); return -1; } byte_modulo = byte_count; /* This many bytes per sample */ byte_count = wfile->wavinfo.Samples * byte_modulo; /* Total bytes to process */ total_bytes = byte_count; /* Seek to requested start sample */ sound_lseek(wfile->fd,wfile->StartSample*byte_modulo,SEEK_CUR); for (; byte_count > 0 && wfile->wavinfo.DataBytes > 0; byte_count -= (UInt32) n ) { bytes = (int) ( byte_count > dfile->dspblksiz ? dfile->dspblksiz : byte_count ); if ( bytes > wfile->wavinfo.DataBytes ) /* Size bigger than data chunk? */ bytes = wfile->wavinfo.DataBytes; /* Data chunk only has this much left */ // printf("play databytes:%d bytes:%d n:%d\n",wfile->wavinfo.DataBytes,bytes,n); if ( (n = sound_read(wfile->fd,dfile->dspbuf,bytes)) != bytes ) { if ( n >= 0 ) printf("Unexpected EOF reading samples from WAV file\n"); else printf("Reading samples from WAV file\n"); goto errxit; } // printf("pcm writeing data\n");//treckle if (pcm_write(dfile->dspbuf,n) <= 0) { printf("Writing samples data failed\n"); goto errxit; } // printf("end pcm writeing data\n");//treckle wfile->wavinfo.DataBytes -= (UInt32) bytes; /* We have fewer bytes left to read */ //printf("dspblksize=%d bytes=%d DataBytes=%d\n", dfile->dspblksiz, bytes, wfile->wavinfo.DataBytes); } return 0; /* All samples played successfully */ errxit: return -1; /* Indicate error return */ }
int main (void) { clunet_init(); clunet_set_on_data_received(data_received); time_init(); sei(); //eeprom_write_dword((void*)0, 0); record_num = eeprom_read_dword((void*)0); // Читаем кол-во записей mode_current = eeprom_read_byte((void*)4); // Режим mode_temp = eeprom_read_byte((void*)5); // Временный режим disk_initialize(0); unset_bit(DDRA, 3); set_bit(PORTA, 3); // Определение сигнала в линии //unset_bit(DDRA, 4); unset_bit(PORTA, 4); // Открывалка двери, напрямую set_bit(DDRA, 4); unset_bit(PORTA, 4); // Открывалка двери, через реле set_bit(DDRA, 5); HANGUP; // Реле снимания трубки set_bit(DDRA, 6); MODE_NORMAL; // Реле выбора режима unset_bit(DDRG, 0); set_bit(PORTG, 0); // Определение, лежит ли трубка set_bit(DDRD, 6); set_bit(DDRD, 7); // Светодиоды unset_bit(DDRA, 7); set_bit(PORTA, 7); // Счётчик оборотов диска unset_bit(DDRF, 0); // ADC+ unset_bit(PORTF, 0); unset_bit(DDRF, 1); // ADC- unset_bit(PORTF, 1); beep(500, 200); beep(1500, 200); beep(3000, 200); _delay_ms(1000); if (play_wav_pgm(STARTED_WAV) == 0) { LED_GREEN_ON; while (sound_read() >= 0) ; LED_GREEN_OFF; sound_stop(); } else { LED_RED_ON; beep(3000, 200); beep(1500, 200); beep(500, 200); LED_RED_OFF; } send_current_mode(CLUNET_BROADCAST_ADDRESS); while(1) { if (is_LINE_POWER()) incoming_ring(); if (OFFHOOK) control_mode(); transfer_data(); // Передаём данные на досуге. } }
static BYTE sfx_soundexpander_sound_read(WORD addr) { BYTE value = 0; sfx_soundexpander_sound_device.io_source_valid = 0; if (addr == 0x60) { sfx_soundexpander_sound_device.io_source_valid = 1; value = sound_read(sfx_soundexpander_sound_chip_offset, 0); } return value; }
static BYTE sfx_soundexpander_sound_read(WORD addr) { BYTE value = 0; sfx_soundexpander_sound_device.io_source_valid = 0; if (addr == 0x60) { if ((sfx_soundexpander_chip == 3812 && YM3812_chip) || (sfx_soundexpander_chip == 3526 && YM3526_chip)) { sfx_soundexpander_sound_device.io_source_valid = 1; value = sound_read(sfx_soundexpander_sound_chip_offset, 0); } } return value; }
int answer_play(char* filename) // Отвечает и воспроизводит файл { ANSWER; MODE_MYSOUND; _delay_ms(1000); if (play_wav_pgm(filename) == 0) { while (sound_read() >= 0) { if (!LINE_POWER || OFFHOOK) // Сняли трубку, или сигнал исчез { sound_stop(); return 1; } } sound_stop(); } return 0; }
int main() { FILE *fp_file; /* ファイル書き込み用ファイルポインタ */ int count; /* 音声入力 */ sound_open(); fprintf(stderr, ";; Start recording\n"); count = sound_read((char *) buf, BUFSIZE); fprintf(stderr, ";; %d byte are recorded\n", count); sound_close(); /****************************/ /* 音声ファイルの書き出し */ /****************************/ /* ファイルを書きだし専用でオープンする */ fp_file = fopen("test.raw", "wb"); if (fp_file == NULL) { /* エラー処理 */ perror("file open failed"); return 1; } /* 音声データを書き込む */ count = fwrite(buf, sizeof(short), BUFSIZE / sizeof(short), fp_file); if (count != BUFSIZE / sizeof(short)) { /* エラー処理 */ fprintf(stderr, "read count = %d, BUFSIZE = %d, sizeof(buf) = %d\n", count, BUFSIZE, BUFSIZE / sizeof(short)); } /* ファイルをクローズする */ fclose(fp_file); return 1; }
int answer_record(char* filename1, char* filename2, char use_beep) // Отвечает, записывает сообщение, { if (answer_play(filename1)) return 1; // Отвечаем, предлагаем оставить сообщение if (use_beep) beep(3000, 500); // Биип sprintf(buffer, "/%08lu.wav", record_num); // Формируем имя файла clunet_send(CLUNET_BROADCAST_ADDRESS, CLUNET_PRIORITY_INFO, CLUNET_COMMAND_INTERCOM_MESSAGE, (char*)&record_num, sizeof(record_num)); // Отправляем в сеть сообщение record_num++; eeprom_write_dword((void*)0, record_num); // Запоминаем кол-во записей if (rec_wav(buffer) == 0) // Пишем сообщение { int s = 0; long int totalSize = 0; while (s >= 0 && totalSize < 8000UL*RECORD_MAX_LENGTH) { s = sound_write(); totalSize += s; if (!LINE_POWER || OFFHOOK) // Сняли трубку, или сигнал исчез { sound_stop(); return 1; } } sound_stop(); } if (play_wav_pgm(filename2) == 0) // Если пациент дождался, благодарим { while (sound_read() >= 0) { if (!LINE_POWER || OFFHOOK) // Сняли трубку, или сигнал исчез { sound_stop(); return 1; } } sound_stop(); } return 0; }
BYTE digiblaster_read(WORD addr) { return sound_read(digiblaster_sound_chip_offset, 0); }
u8 io_read(u16 adr) { u8 reg = adr & 0x00FF; switch(reg) { case 0x00: return joy_read(); break; case 0x01: /* return serial.sb;*/ break; case 0x02: /* return serial.sc;*/ break; case 0x04: return timers.div; break; case 0x05: return timers.tima; break; case 0x06: return timers.tma; break; case 0x07: return timers.tac; break; case 0x0F: return cpu.irq; break; case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x16: case 0x17: case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3E: case 0x3F: return sound_read(reg); break; case 0x15: case 0x1F: return 0x00; break; case 0x40: return lcd.c; break; case 0x41: return lcd.stat; break; case 0x42: return lcd.scy; break; case 0x43: return lcd.scx; break; case 0x44: return lcd.ly; break; case 0x45: return lcd.lyc; break; case 0x46: return 0xFF; break; case 0x47: return lcd.bgp.b[0]; break; case 0x48: return lcd.obp.b[0]; break; case 0x49: return lcd.obp.b[1]; break; case 0x4A: return lcd.wy; break; case 0x4B: return lcd.wx; break; case 0x4D: return cpu.freq_switch | (cpu.freq == DOUBLE_CPU_FREQ ? 0x80 : 0x00); break; case 0x4F: return ram.selected_vrambank; break; case 0x51: return lcd.hdma_source >> 8; break; case 0x52: return lcd.hdma_source & 0xFF; break; case 0x53: return lcd.hdma_dest >> 8; break; case 0x54: return lcd.hdma_dest & 0xFF; break; case 0x55: return lcd.hdma_length | lcd.hdma_inactive; break; case 0x56: return 0x40; break; case 0x68: return lcd.bgp.s | lcd.bgp.i; break; case 0x69: return lcd.bgp.d[lcd.bgp.s]; break; case 0x6A: return lcd.obp.s | lcd.obp.i; break; case 0x6B: return lcd.obp.d[lcd.obp.s]; break; case 0x70: return ram.rambank_index | 0xF8; break; default:; #ifdef DEBUG printf("Unknown IO read: %.2X\n", reg); #endif } return 0xFF; // Avoids nasty warnings, precious }
BYTE digimax_sound_read(WORD addr) { BYTE value = sound_read((WORD)(digimax_sound_chip_offset | addr), 0); return value; }
/* * Open a WAV file for reading: returns (WAVFILE *) * * The opened file is positioned at the first byte of WAV file data, or * NULL is returned if the open is unsuccessful. */ WAVFILE *WavOpenForRead(const char *Pathname) { WAVFILE *wfile; UInt32 offset; /* File offset */ Byte ubuf[4]; /* 4 byte buffer */ UInt32 dbytes; /* Data byte count */ /* wavfile.c values : */ int channels; /* Channels recorded in this wav file */ u_long samplerate; /* Sampling rate */ int sample_bits; /* data bit size (8/12/16) */ u_long samples; /* The number of samples in this file */ u_long datastart; /* The offset to the wav data */ if(g_wfile) WavClose(g_wfile); wfile = wavfile_alloc(Pathname); if ( wfile == NULL ) return NULL; /* Insufficient memory (class B msg) */ /* * Open the file for reading: */ // printf("Opening WAV file %p\n", wfile->Pathname); if ( (wfile->fd = sound_open(wfile->Pathname,O_RDONLY)) < 0 ) { printf("Opening WAV file %p failed\n", wfile->Pathname); goto errxit; } if ( sound_lseek(wfile->fd,0,SEEK_SET) != 0 ) { printf("Rewinding WAV file %p\n",wfile->Pathname); goto errxit; /* Wav file must be seekable device */ } if ( WaveReadHeader(wfile->fd,&channels,&samplerate,&sample_bits,&samples,&datastart) != 0 ) { printf("Reading WAV header from %p", wfile->Pathname); goto errxit; } /* * Copy WAV data over to WAVFILE struct: */ if ( channels == 2 ) wfile->wavinfo.Channels = Stereo; else wfile->wavinfo.Channels = Mono; wfile->wavinfo.SamplingRate = (UInt32) samplerate; wfile->wavinfo.Samples = (UInt32) samples; wfile->wavinfo.DataBits = (UInt16) sample_bits; wfile->wavinfo.DataStart = (UInt32) datastart; wfile->num_samples = wfile->wavinfo.Samples; offset = wfile->wavinfo.DataStart - 4; /* * Seek to byte count and read dbytes: */ if ( sound_lseek(wfile->fd,offset,SEEK_SET) != offset ) { printf("Seeking to WAV data in %p",wfile->Pathname); goto errxit; /* Seek failure */ } if ( sound_read(wfile->fd,ubuf,4) != 4 ) { printf("Reading dbytes from %s",wfile->Pathname); goto errxit; } /* * Put little endian value into 32 bit value: */ dbytes = ubuf[3]; dbytes = (dbytes << 8) | ubuf[2]; dbytes = (dbytes << 8) | ubuf[1]; dbytes = (dbytes << 8) | ubuf[0]; wfile->wavinfo.DataBytes = dbytes; /* * Open succeeded: */ return wfile; /* Return open descriptor */ /* * Return error after failed open: WavClose*/ errxit: mem_free(wfile); /* Dispose of WAVFILE struct */ return NULL; /* Return error indication */ }