this shit pisses me off so much
This commit is contained in:
parent
8f227b7105
commit
d83a1a98c0
63
pc-outro.c
63
pc-outro.c
|
@ -1,12 +1,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "portaudio.h"
|
#include <ao/ao.h>
|
||||||
|
#include <mpg123.h>
|
||||||
|
|
||||||
void shutdown(int os);
|
void shutdown(int os);
|
||||||
|
|
||||||
void main (void){
|
void main (void){
|
||||||
int os;
|
int os;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
os = 1;
|
os = 1;
|
||||||
#elif TARGET_OS_MAC
|
#elif TARGET_OS_MAC
|
||||||
|
@ -19,15 +18,69 @@ void main (void){
|
||||||
os = 0;
|
os = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("%d", os);
|
mpg123_handle *mh;
|
||||||
|
unsigned char *buffer;
|
||||||
|
size_t buffer_size;
|
||||||
|
size_t done;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
int driver;
|
||||||
|
ao_device *dev;
|
||||||
|
|
||||||
|
ao_sample_format format;
|
||||||
|
int channels, encoding;
|
||||||
|
long rate;
|
||||||
|
|
||||||
|
/* initializations */
|
||||||
|
ao_initialize();
|
||||||
|
driver = ao_default_driver_id();
|
||||||
|
mpg123_init();
|
||||||
|
mh = mpg123_new(NULL, &err);
|
||||||
|
buffer_size = mpg123_outblock(mh);
|
||||||
|
buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));
|
||||||
|
|
||||||
|
/* open the file and get the decoding format */
|
||||||
|
mpg123_open(mh, "outro.mp3");
|
||||||
|
mpg123_getformat(mh, &rate, &channels, &encoding);
|
||||||
|
|
||||||
|
/* set the output format and open the output device */
|
||||||
|
format.bits = mpg123_encsize(encoding) * 8;
|
||||||
|
format.rate = rate;
|
||||||
|
format.channels = channels;
|
||||||
|
format.byte_format = AO_FMT_NATIVE;
|
||||||
|
format.matrix = 0;
|
||||||
|
dev = ao_open_live(driver, &format, NULL);
|
||||||
|
|
||||||
|
/* decode and play */
|
||||||
|
while (mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK){
|
||||||
|
ao_play(dev, buffer, done);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
free(buffer);
|
||||||
|
ao_close(dev);
|
||||||
|
mpg123_close(mh);
|
||||||
|
mpg123_delete(mh);
|
||||||
|
mpg123_exit();
|
||||||
|
ao_shutdown();
|
||||||
|
|
||||||
|
|
||||||
|
printf("Shutting down, goodbye friend!");
|
||||||
|
shutdown(os);
|
||||||
};
|
};
|
||||||
|
|
||||||
void shutdown(int os){
|
void shutdown(int os){
|
||||||
switch(os){
|
switch(os){
|
||||||
|
case 1:
|
||||||
|
system("c:\\windows\\system32\\shutdown /i");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
system("shutdown -h now");
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// TODO: check init system; https://unix.stackexchange.com/questions/18209/detect-init-system-using-the-shell
|
|
||||||
system("shutdown -P now");
|
system("shutdown -P now");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Error: Could not determine OS");
|
printf("Error: Could not determine OS");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue