duma
8th August 2011, 16:51
I have created a program which builds and runs without errors but no window pops up when I run. Can someone please tell me why.
My main function is below:
int main(int argc, char *argv[])
{
struct option long_option[] =
{
{"help", 0, NULL, 'h'},
{"device", 1, NULL, 'D'},
{"rate", 1, NULL, 'r'},
{"channels", 1, NULL, 'c'},
{"frequency", 1, NULL, 'f'},
{"buffer", 1, NULL, 'b'},
{"period", 1, NULL, 'p'},
{"method", 1, NULL, 'm'},
{"format", 1, NULL, 'o'},
{"verbose", 1, NULL, 'v'},
{"noresample", 1, NULL, 'n'},
{"pevent", 1, NULL, 'e'},
{NULL, 0, NULL, 0},
};
int err;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
int method = 0;
snd_pcm_t *handle;
snd_pcm_channel_area_t *areas;
signed short *samples;
unsigned int chn;
snd_pcm_hw_params_alloca(&hwparams);
snd_pcm_sw_params_alloca(&swparams);
err = snd_output_stdio_attach(&output, stdout, 0);
if (err < 0) {
printf("Output failed: %s\n", snd_strerror(err));
return 0;
}
/* cout<<"Playback device is %s "<<","<< device);
cout<<"Stream parameters are %iHz, %s, %i channels "<<","<< rate<<","<< snd_pcm_format_name(format), channels;
cout<<"Sine wave rate is %.4fHz "<<","<< freq;
cout<<"Using transfer method: %s "<<","<< transfer_methods[method].name;
*/
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
return 0;
}
if ((err = set_hwparams(handle, hwparams, transfer_methods[method].access)) < 0) {
printf("Setting of hwparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = set_swparams(handle, swparams)) < 0) {
printf("Setting of swparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose > 0)
snd_pcm_dump(handle, output);
samples = new signed short[(period_size * channels * snd_pcm_format_physical_width(format))];
if (samples == NULL) {
printf("Not enough memory\n");
exit(EXIT_FAILURE);
}
areas = new snd_pcm_channel_area_t [channels];
if (areas == NULL) {
printf("Not enough memory\n");
exit(EXIT_FAILURE);
}
for (chn = 0; chn < channels; chn++) {
areas[chn].addr = samples;
areas[chn].first = chn * snd_pcm_format_physical_width(format);
areas[chn].step = channels * snd_pcm_format_physical_width(format);
}
err = transfer_methods[method].transfer_loop(handle, samples, areas);
if (err < 0)
printf("Transfer failed: %s\n", snd_strerror(err));
delete [] areas;
delete [] samples;
snd_pcm_close(handle);
QApplication a(argc, argv);
wave w;
w.setWindowTitle("ESG Wave Creator");
w.show();
return a.exec();
}
My main function is below:
int main(int argc, char *argv[])
{
struct option long_option[] =
{
{"help", 0, NULL, 'h'},
{"device", 1, NULL, 'D'},
{"rate", 1, NULL, 'r'},
{"channels", 1, NULL, 'c'},
{"frequency", 1, NULL, 'f'},
{"buffer", 1, NULL, 'b'},
{"period", 1, NULL, 'p'},
{"method", 1, NULL, 'm'},
{"format", 1, NULL, 'o'},
{"verbose", 1, NULL, 'v'},
{"noresample", 1, NULL, 'n'},
{"pevent", 1, NULL, 'e'},
{NULL, 0, NULL, 0},
};
int err;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
int method = 0;
snd_pcm_t *handle;
snd_pcm_channel_area_t *areas;
signed short *samples;
unsigned int chn;
snd_pcm_hw_params_alloca(&hwparams);
snd_pcm_sw_params_alloca(&swparams);
err = snd_output_stdio_attach(&output, stdout, 0);
if (err < 0) {
printf("Output failed: %s\n", snd_strerror(err));
return 0;
}
/* cout<<"Playback device is %s "<<","<< device);
cout<<"Stream parameters are %iHz, %s, %i channels "<<","<< rate<<","<< snd_pcm_format_name(format), channels;
cout<<"Sine wave rate is %.4fHz "<<","<< freq;
cout<<"Using transfer method: %s "<<","<< transfer_methods[method].name;
*/
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
return 0;
}
if ((err = set_hwparams(handle, hwparams, transfer_methods[method].access)) < 0) {
printf("Setting of hwparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = set_swparams(handle, swparams)) < 0) {
printf("Setting of swparams failed: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose > 0)
snd_pcm_dump(handle, output);
samples = new signed short[(period_size * channels * snd_pcm_format_physical_width(format))];
if (samples == NULL) {
printf("Not enough memory\n");
exit(EXIT_FAILURE);
}
areas = new snd_pcm_channel_area_t [channels];
if (areas == NULL) {
printf("Not enough memory\n");
exit(EXIT_FAILURE);
}
for (chn = 0; chn < channels; chn++) {
areas[chn].addr = samples;
areas[chn].first = chn * snd_pcm_format_physical_width(format);
areas[chn].step = channels * snd_pcm_format_physical_width(format);
}
err = transfer_methods[method].transfer_loop(handle, samples, areas);
if (err < 0)
printf("Transfer failed: %s\n", snd_strerror(err));
delete [] areas;
delete [] samples;
snd_pcm_close(handle);
QApplication a(argc, argv);
wave w;
w.setWindowTitle("ESG Wave Creator");
w.show();
return a.exec();
}