📄 sound.h
字号:
/* gameplaySP * * Copyright (C) 2006 Exophase <exophase@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#ifndef SOUND_H#define SOUND_H#define BUFFER_SIZE 65536// A lot of sound cards on PC can't handle such small buffers but this// seems to work well on PSP.#ifdef PSP_BUILD#define SOUND_BUFFER_SIZE 4096#else#define SOUND_BUFFER_SIZE 16384#endiftypedef enum{ DIRECT_SOUND_INACTIVE, DIRECT_SOUND_RIGHT, DIRECT_SOUND_LEFT, DIRECT_SOUND_LEFTRIGHT} direct_sound_status_type;typedef enum{ DIRECT_SOUND_VOLUME_50, DIRECT_SOUND_VOLUME_100} direct_sound_volume_type;typedef struct{ s8 fifo[32]; u32 fifo_base; u32 fifo_top; fixed16_16 fifo_fractional; // The + 1 is to give some extra room for linear interpolation // when wrapping around. u32 buffer_index; direct_sound_status_type status; direct_sound_volume_type volume; u32 last_cpu_ticks;} direct_sound_struct;typedef enum{ GBC_SOUND_INACTIVE, GBC_SOUND_RIGHT, GBC_SOUND_LEFT, GBC_SOUND_LEFTRIGHT} gbc_sound_status_type;typedef struct{ u32 rate; fixed16_16 frequency_step; fixed16_16 sample_index; fixed16_16 tick_counter; u32 total_volume; u32 envelope_initial_volume; u32 envelope_volume; u32 envelope_direction; u32 envelope_status; u32 envelope_step; u32 envelope_ticks; u32 envelope_initial_ticks; u32 sweep_status; u32 sweep_direction; u32 sweep_ticks; u32 sweep_initial_ticks; u32 sweep_shift; u32 length_status; u32 length_ticks; u32 noise_type; u32 wave_type; u32 wave_bank; u32 wave_volume; gbc_sound_status_type status; u32 active_flag; u32 master_enable; s8 *sample_data;} gbc_sound_struct;extern direct_sound_struct direct_sound_channel[2];extern gbc_sound_struct gbc_sound_channel[4];extern s8 square_pattern_duty[4][8];extern u32 gbc_sound_master_volume_left;extern u32 gbc_sound_master_volume_right;extern u32 gbc_sound_master_volume;extern u32 sound_frequency;extern u32 sound_on;extern u32 global_enable_audio;extern u32 enable_low_pass_filter;extern u32 audio_buffer_size_number;extern SDL_mutex *sound_mutex;extern SDL_cond *sound_cv;void sound_timer_queue8(u32 channel, u8 value);void sound_timer_queue16(u32 channel, u16 value);void sound_timer_queue32(u32 channel, u32 value);void sound_timer(fixed16_16 frequency_step, u32 channel);void sound_reset_fifo(u32 channel);void update_gbc_sound(u32 cpu_ticks);void init_sound();void sound_write_mem_savestate(file_tag_type savestate_file);void sound_read_savestate(file_tag_type savestate_file);#define gbc_sound_tone_control_low(channel, address) \{ \ u32 initial_volume = (value >> 12) & 0x0F; \ u32 envelope_ticks = ((value >> 8) & 0x07) * 4; \ gbc_sound_channel[channel].length_ticks = 64 - (value & 0x3F); \ gbc_sound_channel[channel].sample_data = \ square_pattern_duty[(value >> 6) & 0x03]; \ gbc_sound_channel[channel].envelope_direction = (value >> 11) & 0x01; \ gbc_sound_channel[channel].envelope_initial_volume = initial_volume; \ gbc_sound_channel[channel].envelope_volume = initial_volume; \ gbc_sound_channel[channel].envelope_initial_ticks = envelope_ticks; \ gbc_sound_channel[channel].envelope_ticks = envelope_ticks; \ gbc_sound_channel[channel].envelope_status = (envelope_ticks != 0); \ gbc_sound_channel[channel].envelope_volume = initial_volume; \ gbc_sound_update = 1; \ address16(io_registers, address) = value; \} \#define gbc_sound_tone_control_high(channel, address) \{ \ u32 rate = value & 0x7FF; \ gbc_sound_channel[channel].rate = rate; \ gbc_sound_channel[channel].frequency_step = \ float_to_fp16_16(((131072.0 / (2048 - rate)) * 8.0) / sound_frequency); \ gbc_sound_channel[channel].length_status = (value >> 14) & 0x01; \ if(value & 0x8000) \ { \ gbc_sound_channel[channel].active_flag = 1; \ gbc_sound_channel[channel].sample_index -= float_to_fp16_16(1.0 / 12.0); \ gbc_sound_channel[channel].envelope_ticks = \ gbc_sound_channel[channel].envelope_initial_ticks; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -