Code:
#include <stdio.h>
#include <conio.h>
void timer ( int h,int l);
void speaker (unsigned char sndh, int del);
void custom (int amount);
int main()
{
int high[8] = {0x98, 0x00, 0xCA, 0xE9, 0xDA, 0x1F, 0x3A, 0xE4};
int low[8] = {0x0A, 0x0A, 0x11, 0x08, 0x0F, 0x0E, 0x0D, 0x0B};
int sequence[25] = {2, 2, 4, 2, 6, 5, 2,2, 4, 2, 7, 6, 2, 2, 3, 0, 6, 5, 4, 1, 1, 0, 6, 7, 6};
int delarray[25] = {500,500, 1000, 1000, 1000, 2000, 500, 500, 1000, 1000, 1000, 2000, 500, 500, 1000, 1000, 1000, 1000, 3000, 500, 500, 1000, 1000, 1000, 2000};
unsigned char pthold = inp(0x43), logical, sndhold = inp(0x61);
int delay = 0, select = 0, i, amt;
printf("\n\nMusic Program\n");
printf("--------------------------------------\n\n");
printf("1.\t Play Happy Birthday\n");
printf("2.\t Enter your own notes\n");
printf("\n\n--------------------------------------\n\n");
printf("Enter selection please: ");
scanf("%d", &select);
if(select == 2)
{
printf("Please enter amount of notes: ");
scanf("%d", &amt);
custom(amt);
}
else if(select == 1)
{
for(i = 0; i < 25; i++)
{
timer(high[sequence[i]], low[sequence[i]]);
speaker(sndhold, delarray[i]);
}
}
}
void custom (int amount)
{
int *custh, *custl, *delarray;
int i;
unsigned char pthold = inp(0x43), logical, sndhold = (0x61);
(*custh) = new int[amount];
(*custl) = new int[amount];
(*delarray) = new int[amount];
printf("Please enter the high, low values for the notes and the delay:\n");
for(i = 0; i < amount; i++)
{
printf("High value #%d: ", i + 1);
scanf("%d", &custh[i]);
printf("Low value #%d: ", i + 1);
scanf("%d", &custl[i]);
printf("Delay of #%dst value: ", i + 1);
scanf("%d", &delarray[i]);
}
outp(0x43, pthold | 0xB6);
for(i = 0; i < amount; i++)
{
timer(custh[i], custl[i]);
speaker(sndhold, delarray[i]);
}
}
void timer (int h, int l)
{
outp(0x42, h);
outp(0x42, l);
}
void speaker (unsigned char sndh, int del)
{
outp(0x61, sndh | 0x23);
delay(del);
outp(0x61, sndh);
}
The program is supposed to play "happy birthday" over the pc speaker, what I'm attempting to do is