@@ -60,10 +60,10 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
60
60
synth.allowEmptyBuffers (true );
61
61
62
62
mic = adc.getChannel (microphone, false );
63
- adc.setSamplePeriod ( 1e6 / 22000 );
64
- mic->setGain (7 ,0 );
63
+ adc.setSamplePeriod ( 1e6 / 11000 );
64
+ mic->setGain (7 , 0 );
65
65
66
- // Implementers note: The order that the pipeline comes up here is quite senitive . If we connect up to splitters after starting to
66
+ // Implementers note: The order that the pipeline comes up here is quite sensitive . If we connect up to splitters after starting to
67
67
// listen for events from them, we'll see channel startup events (which are valid!) that we don't want. So roughly always follow
68
68
// the following schema:
69
69
//
@@ -74,14 +74,18 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
74
74
// This prevents any cases where the pipeline stages cause a connect() message to be emitted, which then auto-activates the mic.
75
75
76
76
// Initialialise the microphone filter
77
- micFilter = new LowPassFilter (mic->output , 0 .1f , true );
77
+ // micFilter = new LowPassFilter(mic->output, 0.35f , true);
78
78
79
79
// Initilise input splitter
80
- rawSplitter = new StreamSplitter (*micFilter);
80
+ // rawSplitter = new StreamSplitter(*micFilter);
81
+ rawSplitter = new StreamSplitter (mic->output );
81
82
82
83
// Initilise stream normalizer
83
84
processor = new StreamNormalizer (*rawSplitter->createChannel (), 0 .08f , true , DATASTREAM_FORMAT_8BIT_SIGNED, 10 );
84
85
86
+ // Initilise level detector SPL and attach to splitter
87
+ levelSPL = new LevelDetectorSPL (*rawSplitter->createChannel (), 85.0 , 65.0 , 16.0 , 0 , DEVICE_ID_MICROPHONE, false );
88
+
85
89
// Connect to the rawSplitter. This must come AFTER the processor, to prevent the processor's channel activation starting the microphone
86
90
if (EventModel::defaultEventBus)
87
91
EventModel::defaultEventBus->listen (rawSplitter->id , DEVICE_EVT_ANY, this , &MicroBitAudio::onSplitterEvent, MESSAGE_BUS_LISTENER_IMMEDIATE);
@@ -92,26 +96,30 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
92
96
// Initilise level detector and attach to splitter
93
97
level = new LevelDetector (*splitter->createChannel (), 150 , 75 , DEVICE_ID_SYSTEM_LEVEL_DETECTOR, false );
94
98
95
- // Initilise level detector SPL and attach to splitter
96
- levelSPL = new LevelDetectorSPL (*rawSplitter->createChannel (), 85.0 , 65.0 , 16.0 , 0 , DEVICE_ID_MICROPHONE, false );
97
-
98
99
// Connect to the splitter - this COULD come after we create it, before we add any stages, as these are dynamic and will only connect on-demand, but just in case
99
100
// we're going to follow the schema set out above, to be 100% sure.
100
101
if (EventModel::defaultEventBus)
101
102
EventModel::defaultEventBus->listen (DEVICE_ID_SPLITTER, DEVICE_EVT_ANY, this , &MicroBitAudio::onSplitterEvent, MESSAGE_BUS_LISTENER_IMMEDIATE);
103
+
104
+ // activateMic();
102
105
}
103
106
104
107
/* *
105
108
* Handle events from splitter
106
109
*/
107
110
void MicroBitAudio::onSplitterEvent (MicroBitEvent e){
108
- if ( e.value == SPLITTER_CHANNEL_CONNECT )
111
+
112
+ DMESGF ( " Event! (%d -> %d)" , e.source , e.value );
113
+
114
+ if ( e.value == SPLITTER_ACTIVATE || e.value == SPLITTER_CHANNEL_CONNECT )
109
115
activateMic ();
110
116
111
117
// Note: The processor will always be present on the rawSplitter, hence the <= 1.
112
- else if ( e.value == SPLITTER_CHANNEL_DISCONNECT )
113
- if ( splitter->numberActiveChannels <= 0 && rawSplitter->numberActiveChannels <= 1 )
118
+ else if ( e.value == SPLITTER_DEACTIVATE || e.value == SPLITTER_CHANNEL_DISCONNECT )
119
+ {
120
+ if ( splitter->activeChannels < 1 )
114
121
deactivateMic ();
122
+ }
115
123
}
116
124
117
125
/* *
@@ -138,14 +146,14 @@ void MicroBitAudio::deactivateMic(){
138
146
*/
139
147
void MicroBitAudio::deactivateLevelSPL (){
140
148
// levelSPL->disable();
149
+ levelSPL->activateForEvents ( false );
141
150
}
142
151
143
152
/* *
144
153
* Set normaliser gain
145
154
*/
146
155
void MicroBitAudio::setMicrophoneGain (int gain){
147
156
processor->setGain (gain/100 );
148
-
149
157
}
150
158
151
159
/* *
0 commit comments