Exemplo n.º 1
0
void perror(int level, int errnum, const char *args, ...)
{
  va_list ap;

#ifdef _USE_VTCODES
  printf("\e[1m");
#endif
  if(errnum>0)
    {
      if(ERROR_IS_WARNING(errnum))
	printf("Warning: ");
      else
	printf("Error: ");
    }
  va_start(ap, args);  
  vprintf(args, ap);
  va_end(ap);
#ifdef _USE_VTCODES
  printf("\e[0m");
#endif
  printf("\n");

  if(errnum > 0)
    describe_error(errnum);
}
Exemplo n.º 2
0
void
open_device (dspdev_t * dsp)
{
  const char * devdsp;

  if (dsp->fd >= 0)
     close_device (dsp);

  dsp->format = 0; dsp->channels = 0; dsp->speed = 0;

  if ((devdsp = getenv("OSS_AUDIODEV")) == NULL)
     devdsp = "/dev/dsp";

  if (raw_mode)
    dsp->flags |= O_EXCL;	/* Disable redirection to the virtual mixer */

  if (dsp->dname[0] == '\0') strcpy (dsp->dname, devdsp);

  if ((dsp->fd = open (dsp->dname, dsp->flags, 0)) == -1)
    {
      perror_msg (dsp->dname);
      describe_error ();
      exit (E_SETUP_ERROR);
    }

  if (raw_mode)
    {
      /*
       * Disable sample rate/format conversions.
       */
      int tmp = 0;
      ioctl (dsp->fd, SNDCTL_DSP_COOKEDMODE, &tmp);
    }
}
Exemplo n.º 3
0
intmax_t           handle_error                  (uintmax_t eflag, intmax_t errnum){ // {{{
        const char *errmsg;
	// check global_settings
 	       
	if( (errmsg = describe_error(errnum)) == NULL)
		goto exit;
	
	fprintf(stderr, "%s\n", errmsg);
exit:
	return errnum;
} // }}}
Exemplo n.º 4
0
int
test_device(char *dn, int flags, testcfg_t *tcfg)
{
    oss_audioinfo ainfo;
    int code;
    int fd;

    fd = open(dn, O_WRONLY, 0);
    if (fd == -1) {
        int err = errno;
        perror(dn);
        errno = err;
        describe_error(errno);
        return (0);
    }

    ainfo.dev = -1;
    if (ioctl(fd, SNDCTL_AUDIOINFO, &ainfo) == -1) {
        perror("SNDCTL_AUDIOINFO");
        (void) close(fd);
        return (1);
    }

    (void) printf(_("\n*** Scanning sound adapter #%d ***\n"),
                  ainfo.card_number);

    (void) printf(_("%s (audio engine %d): %s\n"), ainfo.devnode, ainfo.dev,
                  ainfo.name);

    if (!ainfo.enabled) {
        (void) printf(_("  - Device not present - Skipping\n"));
        (void) close(fd);
        return (1);
    }

    if (!(ainfo.caps & PCM_CAP_OUTPUT)) {
        (void) printf(_("  - Skipping input only device\n"));
        (void) close(fd);
        return (1);
    }

    (void) printf(_("  - Performing audio playback test... "));
    (void) fflush(stdout);

    code = testdsp(fd, flags, tcfg);
    (void) close(fd);

    return (code == 1);
}
Exemplo n.º 5
0
/* main program */
int main(int argc, char* argv[]) 
{
    cl_float a_data[LENGTH];
    cl_float b_data[LENGTH];
    cl_float c_res [LENGTH];

    cl_int rval;

    size_t domain_size[1];    /* global domain size */
    size_t workgroup_size[1];

    cl_device_id device_id;
    cl_context context;
    cl_command_queue commands;
    cl_program program_obj;
    cl_kernel kernel;
    
    cl_mem a_in;     /* device memory for input vector a */
    cl_mem b_in;     /* device memory for input vector b */
    cl_mem c_out;    /* device memory for output vector c */
    
    cl_uint count = LENGTH;

    double start_time, end_time;

    /* fill input vectors with random values */
    for(int i = 0; i < count; ++i){
        a_data[i] = rand() / (cl_float)RAND_MAX;
        b_data[i] = rand() / (cl_float)RAND_MAX;
    }

    start_time = get_time();
    
    cl_platform_id platform;
    rval = clGetPlatformIDs(1, &platform, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Could not get platform", rval);
    rval = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Could not get device ID", rval);
    printf("Compute device:\n");
    output_device_info(stdout, device_id, CL_FALSE);
  
    /* create compute context */
    context = clCreateContext(0, 1, &device_id, NULL, NULL, &rval);
    if ((rval != CL_SUCCESS) || (context == NULL))
        error_exit("Could not create compute context", rval);

    /* create command queue */
    commands = clCreateCommandQueue(context, device_id, 0, &rval);
    if ((rval != CL_SUCCESS) || (commands == NULL))
        error_exit("Could not create command queue", rval);

    /* create compute program object from source buffer */
    program_obj = clCreateProgramWithSource(context, 
            1, (const char **) &kernel_source, NULL, &rval);
    if ((rval != CL_SUCCESS) || (program_obj == NULL))
        error_exit("Could not create program object from source", rval);

    /* build program object */
    rval = clBuildProgram(program_obj, 0, NULL, NULL, NULL, NULL);
    if (rval != CL_SUCCESS) {
        size_t len;
        char buffer[2048];

        describe_error("Could not build executable", rval, stderr);
        clGetProgramBuildInfo(program_obj, device_id, CL_PROGRAM_BUILD_LOG, 
                sizeof(buffer), buffer, &len);
        fprintf(stderr, "%s\n", buffer);
        return EXIT_FAILURE;
    }

    /* create compute kernel from program object */
    kernel = clCreateKernel(program_obj, "vadd", &rval);
    if ((rval != CL_SUCCESS) || (kernel  == NULL))
        error_exit("Could not create compute kernel", rval);

    end_time = get_time();
    printf("\nInitialization time %f seconds\n", end_time - start_time);

    start_time = get_time();

    /* create input (a, b) and output (c) arrays in device memory  */
    a_in = clCreateBuffer(context,  CL_MEM_READ_ONLY,  
            sizeof(cl_float) * count, NULL, NULL);
    b_in = clCreateBuffer(context,  CL_MEM_READ_ONLY,  
            sizeof(cl_float) * count, NULL, NULL);
    c_out= clCreateBuffer(context,  CL_MEM_WRITE_ONLY, 
            sizeof(cl_float) * count, NULL, NULL);
    if ((a_in == NULL) || (b_in == NULL) || (c_out== NULL))
        error_exit("Could not allocate device memory", rval);
    
    /* write a and b vectors into compute device memory */
    rval = clEnqueueWriteBuffer(commands, a_in, CL_TRUE, 0, 
            sizeof(cl_float) * count, a_data, 0, NULL, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Could not copy a_data to device memory", rval);
    rval = clEnqueueWriteBuffer(commands, b_in, CL_TRUE, 0, 
            sizeof(cl_float) * count, b_data, 0, NULL, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Could not copy b_data to device memory", rval);

    end_time = get_time();
    printf("Time to copy data %f seconds\n", end_time - start_time);
    
    /* set arguments to compute kernel */
    rval = 0;
    rval  = clSetKernelArg(kernel, 0, sizeof(cl_mem), &a_in);
    rval |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &b_in);
    rval |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &c_out);
    rval |= clSetKernelArg(kernel, 3, sizeof(count), &count);
    if (rval != CL_SUCCESS)
        error_exit("Could not set kernel arguments", rval);

    /* get maximum work group size for executing kernel on device */
    rval = clGetKernelWorkGroupInfo(kernel, device_id, 
            CL_KERNEL_WORK_GROUP_SIZE, 
            sizeof(workgroup_size[0]), workgroup_size, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Could not retrieve kernel work group info", rval);

    start_time = get_time();
    
    /* execute kernel over entire range of 1d input data set
       using maximum number of work group items for device */
    domain_size[0] = count;
    rval = clEnqueueNDRangeKernel(commands, kernel, 1, NULL, 
            domain_size, workgroup_size, 0, NULL, NULL);
    if (rval != CL_SUCCESS)
        error_exit("Failed to execute kernel", rval); 

    /* wait for commands to complete before reading back results */
    clFinish(commands);

    end_time = get_time();
    printf("TIme for kernel computation %f seconds\n", end_time - start_time);

    /* read back results from compute device */
    rval = clEnqueueReadBuffer(commands, c_out, CL_TRUE, 0, 
            sizeof(cl_float) * count, c_res, 0, NULL, NULL);  
    if (rval != CL_SUCCESS)
        error_exit("Could not read output array", rval);
    
    /* check results */
    int correct = 0;
    cl_float diff;
    for(cl_uint i = 0; i < count; ++i)
    {
        diff = a_data[i] + b_data[i];
        diff -= c_res[i];
        if(diff*diff < TOL*TOL)
            ++correct;
        else {
            printf("difference %f in element %d:  a %f b %f c %f\n",
                    diff, i, a_data[i], b_data[i], c_res[i]);
        }
    }
    
    /* summarize results */
    printf("\nC = A+B:  %d out of %d results were correct\n", 
            correct, count);
    
    /* clean up */
    clReleaseMemObject(a_in);
    clReleaseMemObject(b_in);
    clReleaseMemObject(c_out);
    clReleaseProgram(program_obj);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(commands);
    clReleaseContext(context);

    return EXIT_SUCCESS;
}
Exemplo n.º 6
0
static ERL_NIF_TERM make_error_tuple(ErlNifEnv* env, int err) {
  return enif_make_tuple2(env, ATOM_ERROR, describe_error(env, err));
}
Exemplo n.º 7
0
int
main(int argc, char *argv[])
{
    int t, i;
    int maxdev;
    int flags = 0;
    int status = 0;
    int numdev;
    extern int optind;
    testcfg_t	*tcfg;

    (void) setlocale(LC_ALL, "");
    (void) textdomain(TEXT_DOMAIN);

    tcfg = &test_stereo;

    /*
     * Simple command line switch handling.
     */

    while ((i = getopt(argc, argv, "l2457")) != EOF) {
        switch (i) {
        case 'l':
            flags |= TF_LOOP;
            break;
        case '2':
            tcfg = &test_stereo;
            break;
        case '4':
            tcfg = &test_quad;
            break;
        case '5':
            tcfg = &test_51;
            break;
        case '7':
            tcfg = &test_71;
            break;
        default:
            (void) printf(_("Usage: %s [options...] [device]\n"
                            "	-2	Stereo test\n"
                            "	-4	Quadraphonic 4.0 test\n"
                            "	-5	Surround 5.1 test\n"
                            "	-7	Surround 7.1 test\n"
                            "	-l	Loop test\n"), argv[0]);
            exit(-1);
        }
    }

    /*
     * Open the mixer device used for calling SNDCTL_SYSINFO and
     * SNDCTL_AUDIOINFO.
     */
    if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1) {
        int err = errno;
        perror("/dev/mixer");
        errno = err;
        describe_error(errno);
        exit(-1);
    }

    prepare(tcfg);			/* Prepare the wave data */

    /*
     * Enumerate all devices and play the test sounds.
     */
    maxdev = find_num_devices();
    if (maxdev < 1) {
        (void) printf(_("\n*** No audio hardware available ***\n"));
        exit(-1);
    }

    numdev = (argc - optind);
    do {
        char *dn;
        oss_audioinfo	ainfo;

        if (numdev > 0) {
            for (t = 0; t < numdev; t++) {
                dn = argv[optind + t];
                if (!test_device(dn, flags, tcfg))
                    status++;
            }
        } else {
            for (t = 0; t < maxdev; t++) {
                ainfo.dev = t;
                if (ioctl(mixerfd, SNDCTL_AUDIOINFO,
                          &ainfo) == -1) {
                    perror("SNDCTL_AUDIOINFO");
                    status++;
                    continue;
                }
                dn = ainfo.devnode;
                if (!test_device(dn, flags, tcfg))
                    status++;
            }
        }

        if (status == 0)
            (void) printf(_("\n*** All tests completed OK ***\n"));
        else
            (void) printf(_("\n*** Errors were detected ***\n"));

    } while (flags & TF_LOOP);

    (void) close(mixerfd);

    return (status);
}
Exemplo n.º 8
0
int main(int argc, char** argv) {
    if(argc != 2 && argc != 3) {
        c_print_format("Usage: %s FILE [cartridge/folder]\n", argv[0]);
        return 0;
    }
    Arena arena = arena_create(MB(512));

    String cartridge_folder_path_name = (argc > 2)
        ? string_from_c_string(argv[2])
        : L("SuperMarioWorld.sfc");
    Path cartridge_folder_path;
    path_init(&cartridge_folder_path, cartridge_folder_path_name);
    Path manifest_path;
    path_init_from_c(&manifest_path, &cartridge_folder_path, "manifest.bml");
    Buffer manifest_buffer = path_read_file(&manifest_path, &arena);

    Wdc65816MapperBuilder rom_builder = { };
    
    char name[256];
    Buffer name_buffer = buffer(name, 256);
    Buffer rom_buffer;
    for(Wdc65816RomLoader loader = wdc65816_rom_loader_begin(&rom_builder,
                                                             string_from_buffer(manifest_buffer));
        wdc65816_rom_loader_end(&loader);
        wdc65816_rom_loader_next(&loader)) {
        Wdc65816MemoryBufferRequest request = wdc65816_rom_loader_get_buffer_request(&loader,
                                                                                     name_buffer);
        Buffer file_buffer = buffer(arena_alloc_array(&arena, request.size, u8), request.size);
        if(string_equal(request.name, L("program.rom")) &&
           request.type == WDC65816_MEMORY_ROM) {
            rom_buffer = file_buffer;
        }
        wdc65816_rom_loader_set_buffer(&loader, file_buffer);
    }

    uint mapper_buffer_size = wdc65816_mapper_get_buffer_size();
    u8* work_buffer = arena_alloc_array(&arena, mapper_buffer_size, u8);
    Wdc65816Mapper rom;
    wdc65816_mapper_init(&rom, &rom_builder, (u8**)work_buffer);

    nuts_global_init();

    Path working_dir;
    path_init_working_directory(&working_dir);
    FreeList sentinel;
    free_list_init(&sentinel);
    ErrorList error_list;
    error_list_init(&error_list, arena_subarena(&arena, MB(10)));


    AST ast;
    ast_init(&ast, &arena);
    String file_name = string_from_c_string(argv[1]); 
    /* struct timespec lex_start,      lex_end,      lex_time = { 0 }; */
    /* struct timespec parse_start,    parse_end,    parse_time = { 0 }; */
    /* struct timespec assemble_start, assemble_end, assemble_time = { 0 }; */
    /* struct timespec all_start,      all_end,      all_time; */
    

    /* clock_gettime(CLOCK_REALTIME, &all_start); */
    Parser parser;
    parser_init(&parser, &arena, &sentinel, &error_list, &ast);
    int error_num = 0;
    while(1) {
        Path file;
        path_init(&file, file_name);
        Buffer file_buffer = path_read_file(&file, &arena);
        TokenList token_list;
        //c_print_format("read %.*s\n", file_name.length, file_name.data);
        Text file_text = {
            .buffer = file_buffer,
            .name   = file_name
        };
        /* clock_gettime(CLOCK_REALTIME, &lex_start); */
        Result result = lex(file_text, &token_list, &arena, &error_list, &ast.identifier_map);
        if(result == RESULT_ERROR) {
            for(;error_num < error_list.length; error_num++) {
                describe_error(error_list.errors[error_num]);
            }
        }
        /* clock_gettime(CLOCK_REALTIME, &lex_end); */
        /* lex_time = timespec_add(lex_time, timespec_sub(lex_start, lex_end)); */
        /* clock_gettime(CLOCK_REALTIME, &parse_start); */
        /* result = parse(&parser, token_list); */
        /* clock_gettime(CLOCK_REALTIME, &parse_end); */
        /* parse_time = timespec_add(parse_time, timespec_sub(parse_start, parse_end)); */

        if(result == RESULT_NEED_TOKEN_STREAM) {
            file_name = parser.needed_token_stream_file_name;
            continue;
        } else if(result == RESULT_OK) {
            break;
        } else if(result == RESULT_ERROR) {
            for(;error_num < error_list.length; error_num++) {
                describe_error(error_list.errors[error_num]);
            }
            return 1;
        } else {
            invalid_code_path;
        }
    }

    /* clock_gettime(CLOCK_REALTIME, &assemble_start); */
    Assembler assembler;
    assembler_init(&assembler, &error_list, &ast, &rom);
    Result result = RESULT_ERROR;
    while(result != RESULT_OK) {
        result = assemble(&assembler);
        if(result == RESULT_NEED_FILE) {
            String file_name = assembler_get_file_name(&assembler);
            Path file;
            path_init(&file, file_name);
            Buffer file_buffer = path_read_file(&file, &arena);
            assembler_give_buffer(&assembler, file_buffer);
        } else if(result == RESULT_ERROR) {
            break;
        }
    }
    /* clock_gettime(CLOCK_REALTIME, &assemble_end); */
    /* assemble_time = timespec_add(assemble_time, timespec_sub(assemble_start, assemble_end)); */

    for(int i = 0; i < error_list.length; i++) {
        describe_error(error_list.errors[i]);
    }

    /* parser_deinit(&parser); */
    /* clock_gettime(CLOCK_REALTIME, &all_end); */
    /* all_time = timespec_sub(all_start, all_end); */
    /* c_print_format("Lex:      %li.%06lims\n",      lex_time.tv_sec * 1000 +      lex_time.tv_nsec / 1000000,      lex_time.tv_nsec % 1000000); */
    /* c_print_format("Parse:    %li.%06lims\n",    parse_time.tv_sec * 1000 +    parse_time.tv_nsec / 1000000,    parse_time.tv_nsec % 1000000); */
    /* c_print_format("Assemble: %li.%06lims\n", assemble_time.tv_sec * 1000 + assemble_time.tv_nsec / 1000000, assemble_time.tv_nsec % 1000000); */
    /* c_print_format("All:      %li.%06lims\n",      all_time.tv_sec * 1000 +      all_time.tv_nsec / 1000000,      all_time.tv_nsec % 1000000); */

    Path rom_path;
    path_create_from(&rom_path, &cartridge_folder_path, L("program.rom"));
    path_write_file(&rom_path, rom_buffer);
    
    return 0;
}