summaryrefslogtreecommitdiff
path: root/apps/codecs/libgme/sms_fm_apu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libgme/sms_fm_apu.c')
-rw-r--r--apps/codecs/libgme/sms_fm_apu.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/apps/codecs/libgme/sms_fm_apu.c b/apps/codecs/libgme/sms_fm_apu.c
index 6fd00545d6..ee5ce48932 100644
--- a/apps/codecs/libgme/sms_fm_apu.c
+++ b/apps/codecs/libgme/sms_fm_apu.c
@@ -1,82 +1,82 @@
1#include "sms_fm_apu.h" 1#include "sms_fm_apu.h"
2 2
3#include "blargg_source.h" 3#include "blargg_source.h"
4 4
5void Fm_apu_create( struct Sms_Fm_Apu* this ) 5void Fm_apu_create( struct Sms_Fm_Apu* this )
6{ 6{
7 Synth_init( &this->synth ); 7 Synth_init( &this->synth );
8 Ym2413_init( &this->apu ); 8 Ym2413_init( &this->apu );
9} 9}
10 10
11blargg_err_t Fm_apu_init( struct Sms_Fm_Apu* this, int clock_rate, int sample_rate ) 11blargg_err_t Fm_apu_init( struct Sms_Fm_Apu* this, int clock_rate, int sample_rate )
12{ 12{
13 this->period_ = (blip_time_t) (clock_rate / sample_rate); 13 this->period_ = (blip_time_t) (clock_rate / sample_rate);
14 CHECK_ALLOC( !Ym2413_set_rate( &this->apu, sample_rate, clock_rate ) ); 14 CHECK_ALLOC( !Ym2413_set_rate( &this->apu, sample_rate, clock_rate ) );
15 15
16 Fm_apu_set_output( this, 0 ); 16 Fm_apu_set_output( this, 0 );
17 Fm_apu_volume( this, (int)FP_ONE_VOLUME ); 17 Fm_apu_volume( this, (int)FP_ONE_VOLUME );
18 Fm_apu_reset( this ); 18 Fm_apu_reset( this );
19 return 0; 19 return 0;
20} 20}
21 21
22void Fm_apu_reset( struct Sms_Fm_Apu* this ) 22void Fm_apu_reset( struct Sms_Fm_Apu* this )
23{ 23{
24 this->addr = 0; 24 this->addr = 0;
25 this->next_time = 0; 25 this->next_time = 0;
26 this->last_amp = 0; 26 this->last_amp = 0;
27 27
28 Ym2413_reset( &this->apu ); 28 Ym2413_reset( &this->apu );
29} 29}
30 30
31void fm_run_until( struct Sms_Fm_Apu* this, blip_time_t end_time ); 31void fm_run_until( struct Sms_Fm_Apu* this, blip_time_t end_time );
32void Fm_apu_write_data( struct Sms_Fm_Apu* this, blip_time_t time, int data ) 32void Fm_apu_write_data( struct Sms_Fm_Apu* this, blip_time_t time, int data )
33{ 33{
34 if ( time > this->next_time ) 34 if ( time > this->next_time )
35 fm_run_until( this, time ); 35 fm_run_until( this, time );
36 36
37 Ym2413_write( &this->apu, this->addr, data ); 37 Ym2413_write( &this->apu, this->addr, data );
38} 38}
39 39
40void fm_run_until( struct Sms_Fm_Apu* this, blip_time_t end_time ) 40void fm_run_until( struct Sms_Fm_Apu* this, blip_time_t end_time )
41{ 41{
42 assert( end_time > this->next_time ); 42 assert( end_time > this->next_time );
43 43
44 struct Blip_Buffer* const output = this->output_; 44 struct Blip_Buffer* const output = this->output_;
45 if ( !output ) 45 if ( !output )
46 { 46 {
47 this->next_time = end_time; 47 this->next_time = end_time;
48 return; 48 return;
49 } 49 }
50 50
51 blip_time_t time = this->next_time; 51 blip_time_t time = this->next_time;
52 struct Ym2413_Emu* emu = &this->apu; 52 struct Ym2413_Emu* emu = &this->apu;
53 do 53 do
54 { 54 {
55 short samples [2]; 55 short samples [2];
56 Ym2413_run( emu, 1, samples ); 56 Ym2413_run( emu, 1, samples );
57 int amp = (samples [0] + samples [1]) >> 1; 57 int amp = (samples [0] + samples [1]) >> 1;
58 58
59 int delta = amp - this->last_amp; 59 int delta = amp - this->last_amp;
60 if ( delta ) 60 if ( delta )
61 { 61 {
62 this->last_amp = amp; 62 this->last_amp = amp;
63 Synth_offset_inline( &this->synth, time, delta, output ); 63 Synth_offset_inline( &this->synth, time, delta, output );
64 } 64 }
65 time += this->period_; 65 time += this->period_;
66 } 66 }
67 while ( time < end_time ); 67 while ( time < end_time );
68 68
69 this->next_time = time; 69 this->next_time = time;
70} 70}
71 71
72void Fm_apu_end_frame( struct Sms_Fm_Apu* this, blip_time_t time ) 72void Fm_apu_end_frame( struct Sms_Fm_Apu* this, blip_time_t time )
73{ 73{
74 if ( time > this->next_time ) 74 if ( time > this->next_time )
75 fm_run_until( this, time ); 75 fm_run_until( this, time );
76 76
77 this->next_time -= time; 77 this->next_time -= time;
78 assert( this->next_time >= 0 ); 78 assert( this->next_time >= 0 );
79 79
80 if ( this->output_ ) 80 if ( this->output_ )
81 Blip_set_modified( this->output_ ); 81 Blip_set_modified( this->output_ );
82} 82}