Hal Message Wave File

Permalink

Audio files for HAL 9000 are not included here, lest we run afoul of copyright issues, but with just a bit of Google searching you can find an ample supply already in WAV format. Once you have WAV files you're happy with, you'll want to drag and drop them directly onto your CIRCUITPY drive.

Join GitHub today

Macgyver full episodes torrent download full. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Sign up
Branch:master
Find file Copy path
Fetching contributors…
/*
Software Audio PWM
Timer 3 used to create a software audo pwm.
This function is useful when you want to create some audio sounds
and you don't hava a DAC.
With this fast PWM and a RC-Low pass filter you can produce with
minimum efforts audio sounds.
Restrictions and hints:
- with this routine the intterrupt load is double of a hardware PEM impementation
- the voltage after the RC-lowpas has only a range of ~2Vpp because of the interrupt
processing time needs
HAL ( Hardware Abstraction Layer )
Example on how access the HAL within the STM32GENERIC Arduino framework.
contributers and preliminara works by: michael_l, danieleff
June 2015, ChrisMicro
*/
static TIM_HandleTypeDef s_TimerInstance =
{
.Instance = TIM3
};
#defineSOUNDPIN PB0
#defineMEANPERIOD500
#defineDAC_MAX_AMPLITUDE256
//#define SAMPLINGFREQUENCY 44100
#defineWAVEBUFFERLENGTH256
int32_t WaveBuffer[WAVEBUFFERLENGTH];
// this default values will be overwritten
volatileint32_t PeriodLow = 1000;
volatileint32_t PeriodHigh = 1000;
voidsetAmplitude(int32_t amplitude)
{
PeriodLow = MEANPERIOD - amplitude;
PeriodHigh = MEANPERIOD + amplitude;
}
extern'C'voidTIM3_IRQHandler(void)
{
static boolean flag = false;
staticint32_tindex = 0;
if (__HAL_TIM_GET_FLAG(&s_TimerInstance, TIM_FLAG_UPDATE) != RESET)
{
if (__HAL_TIM_GET_IT_SOURCE(&s_TimerInstance, TIM_IT_UPDATE) != RESET)
{
__HAL_TIM_CLEAR_IT(&s_TimerInstance, TIM_IT_UPDATE);
digitalWrite( SOUNDPIN, flag );
if (flag) __HAL_TIM_SET_AUTORELOAD(&s_TimerInstance, PeriodLow);
else
{
__HAL_TIM_SET_AUTORELOAD( &s_TimerInstance, PeriodHigh );
setAmplitude( WaveBuffer[ index++ ] );
if ( index > WAVEBUFFERLENGTH ) index = 0 ;
}
flag = !flag;
}
}
}
voidsetup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SOUNDPIN, OUTPUT);
HAL_NVIC_SetPriority( TIM3_IRQn, 0, 0 );
HAL_NVIC_EnableIRQ ( TIM3_IRQn );
s_TimerInstance.Init.Prescaler = 0; //APB1 TIM3 has 84MHZ, 72MHz
s_TimerInstance.Init.CounterMode = TIM_COUNTERMODE_UP;
s_TimerInstance.Init.Period = 2000 - 1; // prescaler gives 2khz time base
s_TimerInstance.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
s_TimerInstance.Init.RepetitionCounter = 0;
__HAL_RCC_TIM3_CLK_ENABLE();
HAL_TIM_Base_Init ( &s_TimerInstance );
HAL_TIM_Base_Start_IT ( &s_TimerInstance );
// initialize sine wave buffer
for (int n = 0; n < WAVEBUFFERLENGTH; n++)
{
constfloat frequency = 440;
constfloat amplitude = DAC_MAX_AMPLITUDE;
//int32_t val = ( sin( 2 * PI * frequency / SAMPLINGFREQUENCY * n )) * amplitude;
int32_t val = ( sin( 2 * PI * n / WAVEBUFFERLENGTH )) * amplitude;
WaveBuffer[n] = val;
}
}
voidloop()
{
// to noughting, sound is produced in interrupt routine
}
Hal Message Wave File
  • Copy lines
  • Copy permalink

Related Post