1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <string.h>
#include <iostream>
#include <curl/curl.h>
#include <SDL2/SDL.h>
std::string sBuffer;
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
sBuffer.append((char*)buffer, size * nmemb);
return size * nmemb;
}
void SDLAudioCallback(void *data, Uint8 *buffer, int length)
{
memcpy(buffer, sBuffer.data(), length);
sBuffer.erase(0, length);
}
int main() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_Window *window = SDL_CreateWindow("Sample Audio", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
SDL_AudioDeviceID device;
SDL_AudioSpec wantSpec, haveSpec;
SDL_zero(wantSpec);
wantSpec.freq = 22050;
wantSpec.format = AUDIO_U8;
wantSpec.channels = 1;
wantSpec.samples = 2048;
wantSpec.callback = SDLAudioCallback;
device = SDL_OpenAudioDevice(NULL, 0, &wantSpec, &haveSpec, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
if (device == 0)
{
std::cout << "Failed to open audio: " << SDL_GetError() << std::endl;
}
SDL_PauseAudioDevice(device, 0);
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_URL, " https://ssl.hdradios.net:6858/;");
res = curl_easy_perform(curl);
}
SDL_Event event;
bool run = true;
while(run) {
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_QUIT:
run = false;
break;
default:
break;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
| |