Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStream: Add destructor. Enables dynamic creation and destruction. #755

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions teensy3/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,40 @@ audio_block_t * AudioStream::receiveWritable(unsigned int index)
return in;
}

//Define the destructor for AudioStream.
//The contract here is that the user has already disconnected all or
//destroyed all of the AudioConnections. Therefore, the clean-up activities
//that remain are to remove this instance from the update list and
//to release any audio_block_t pointers in this instance's input queue.
AudioStream::~AudioStream(void)
{
//remove this instance from the update list
__disable_irq(); //make sure no update() happens while we're changing the update list
AudioStream *p = first_update;
if (p == this) {
first_update = this->next_update;
} else {
while (p != NULL) {
if (p->next_update == this) {
p->next_update = this->next_update; //remove the pointer to this instance and replace it with the next instance
break;
}
p = p->next_update; //go to next step in linked list
}
}
__enable_irq();

//Since AudioStream is a virtual class, the code seen in this file will only
//be invoked by derive classes. All AudioStream instances have an inputQueue.
//There could be audio blocks assigned to the slots in the inputQueue. The
//derived class should have its own destructor to release() any audio blocks
//in its input queue. In the derived class's destructor, it could look like this:
//for (int i=0; i<num_inputs; i++) {
// audio_block_t *block = inputQueue[i];
// if (block != NULL) release(block);
//}
}

/**************************************************************************************/
// Constructor with no parameters: leave unconnected
AudioConnection::AudioConnection()
Expand Down
1 change: 1 addition & 0 deletions teensy3/AudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class AudioStream
cpu_cycles_max = 0;
numConnections = 0;
}
virtual ~AudioStream(void);
static void initialize_memory(audio_block_t *data, unsigned int num);
int processorUsage(void) { return CYCLE_COUNTER_APPROX_PERCENT(cpu_cycles); }
int processorUsageMax(void) { return CYCLE_COUNTER_APPROX_PERCENT(cpu_cycles_max); }
Expand Down
34 changes: 34 additions & 0 deletions teensy4/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,40 @@ audio_block_t * AudioStream::receiveWritable(unsigned int index)
return in;
}

//Define the destructor for AudioStream.
//The contract here is that the user has already disconnected all or
//destroyed all of the AudioConnections. Therefore, the clean-up activities
//that remain are to remove this instance from the update list and
//to release any audio_block_t pointers in this instance's input queue.
AudioStream::~AudioStream(void)
{
//remove this instance from the update list
__disable_irq(); //make sure no update() happens while we're changing the update list
AudioStream *p = first_update;
if (p == this) {
first_update = this->next_update;
} else {
while (p != NULL) {
if (p->next_update == this) {
p->next_update = this->next_update; //remove the pointer to this instance and replace it with the next instance
break;
}
p = p->next_update; //go to next step in linked list
}
}
__enable_irq();

//Since AudioStream is a virtual class, the code seen in this file will only
//be invoked by derive classes. All AudioStream instances have an inputQueue.
//There could be audio blocks assigned to the slots in the inputQueue. The
//derived class should have its own destructor to release() any audio blocks
//in its input queue. In the derived class's destructor, it could look like this:
//for (int i=0; i<num_inputs; i++) {
// audio_block_t *block = inputQueue[i];
// if (block != NULL) release(block);
//}
}

/**************************************************************************************/
// Constructor with no parameters: leave unconnected
AudioConnection::AudioConnection()
Expand Down
1 change: 1 addition & 0 deletions teensy4/AudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class AudioStream
cpu_cycles_max = 0;
numConnections = 0;
}
virtual ~AudioStream(void);
static void initialize_memory(audio_block_t *data, unsigned int num);
float processorUsage(void) { return CYCLE_COUNTER_APPROX_PERCENT(cpu_cycles); }
float processorUsageMax(void) { return CYCLE_COUNTER_APPROX_PERCENT(cpu_cycles_max); }
Expand Down