Jump to content

Check out our Community Blogs


Member Since 04 Dec 2007
Offline Last Active Feb 18 2013 01:16 AM

Posts I've Made

In Topic: help with ALSA to generate sine wave

07 September 2011 - 08:46 AM


Sorry for intruding on this topic, but I have another problem. I tried to use the code ogopa has provided, but I am getting a random error (at least it looks random.) The error is Input/output error and I believe the error code is -5. Also some times during the while loop, only 70 frames will get written, instead of the intended 128, and that will produce a strange output.

Even if I do not get an error for a few loops (about 20,) no sound come from my speakers.

I have used default as an argument for the program.

Thanks in advance

EDIT: Strange though, when I use hw:0,0 it produces what ogopa described earlier.

In Topic: [Linux] For loop leads to segmentation fault

29 June 2011 - 08:20 AM

Thanks a lot!!!

If I use unsigned char then what would be the best way to deal with the ifstream.read method? It needs to be char. Should I use (char*)a just there?

In Topic: [Linux] For loop leads to segmentation fault

29 June 2011 - 08:04 AM

Why would you have two casts in a row ?

Oh, yes ... That was something I also wanted to ask about. How can I convert a char to int but in the range of 0-255 and not -127 to 127. That was what I was trying to do there

In Topic: [Linux] For loop leads to segmentation fault

29 June 2011 - 08:02 AM

Thanks a million!

That seems to be the solution for both problems, but could you please explain why such a thing has such effects on cout and on that for loop?

In Topic: [Linux] Convert and then convert again and ...

19 June 2011 - 11:19 AM

Thank you very much for the reply,

After making the String-to-Char conversion work as intended and making the changes you suggested I get e compilation error:
sakishrist@sakishrist-laptop:~/Desktop/c++/zlib$ g++ zlib.cpp -o zlib_c -lz
zlib.cpp: In function ‘void _compress(unsigned char*, size_t, unsigned char*, size_t)’:
zlib.cpp:13:16: error: cannot convert ‘unsigned char**’ to ‘Bytef*’ in assignment
zlib.cpp:17:17: error: cannot convert ‘unsigned char**’ to ‘Bytef*’ in assignment

If, on the other hand, I leave the last part out, so that my code looks like this:
#include <iostream>
#include <zlib.h>

using namespace std;

void _compress([B][COLOR=red]unsigned char & in_data[/COLOR][/B], size_t in_size, [B][COLOR=red]unsigned char & out_data[/COLOR][/B], size_t out_size){

z_stream z;

int status;

    z.avail_in = 0;
    z.next_out = &out_data;
    z.avail_out = out_size;

        if ( z.avail_in == 0 ) {
            z.next_in = &in_data;
            z.avail_in = in_size; //dfjngdfng
        if ( z.avail_in != 0 )
            status = deflate( &z, Z_NO_FLUSH );
        int count = out_size - z.avail_out;


int main(){
    unsigned char a[100]="Hello world";    [COLOR=blue]//Although this is not what you suggested I think it works fine but, please correct me if I am wrong.[/COLOR]
    //a=reinterpret_cast<unsigned char>("Hello world!");
    unsigned char b[100];
    cout << b << endl;
    return 0;

Then it compiles OK but I get a runtime error: "Segmentation Fault"

I guess the program tries to access memory that it does not have but ... I don't quite get it. :crying:

Thanks again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download