/* * Build an OpenCL program and store it on the device. * * program - The program to build * device - the device to build the program for * * return - a cl_kernel representing the program */ cl_kernel RiverModelCL::buildProgram(string function) { cl_int error; cout << "Building program" << endl; error = clBuildProgram(program, 1, &device, NULL, NULL, NULL); //checkErr(error, "Erorr building program!", false); // // Get build info // size_t log_size; // Get log size clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size); char build_log[log_size+1]; // Get and output the log clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL); build_log[log_size] = '\0'; cout << build_log << endl; checkErr(error, "Error with build, exiting!", true); cl_kernel kernel = clCreateKernel(program, function.c_str(), &error); checkErr(error, "Create kernel failed!", true); return kernel; }
void ofxQtAudioRecorder::addAudioSamples( float * audioBuffer, int sampleCount){ if(audioMedia != NULL) { printf("adding %i samples\n", sampleCount); OSErr err = BeginMediaEdits(audioMedia); checkErr(0x0201); int bytesPerSample = sizeof(Float32); //printf("bytes %i\n", bytesPerSample); AddMediaSample2(audioMedia, // insert into audio media (UInt8*)audioBuffer, // size sampleCount * bytesPerSample, // number of bytes of audio data kSoundSampleDuration, // normal decode duration 0, // no display offset (won't work anyway) (SampleDescriptionHandle) soundDesc, sampleCount / numChannels, // number of samples 0, // no flags NULL); // not interested in decode time // end media editing and add media to the track EndMediaEdits(audioMedia); checkErr(0x0202); TimeValue trackStart = (TimeValue)(0); InsertMediaIntoTrack(audioTrack, trackStart, 0, GetMediaDuration(audioMedia), fixed1); checkErr(0x0203); //printf("added audio media\n"); } }
void seissol::checkpoint::sionlib::Wavefield::write(const void* header, size_t headerSize) { SCOREP_USER_REGION("CheckPoint_write", SCOREP_USER_REGION_TYPE_FUNCTION); logInfo(rank()) << "Checkpoint backend: Writing."; int file = open(dataFile(odd()), writeMode()); checkErr(file); // Write the header SCOREP_USER_REGION_DEFINE(r_write_header); SCOREP_USER_REGION_BEGIN(r_write_header, "checkpoint_write_header", SCOREP_USER_REGION_TYPE_COMMON); checkErr(sion_coll_fwrite(header, headerSize, 1, file), 1); SCOREP_USER_REGION_END(r_write_header); // Save data SCOREP_USER_REGION_DEFINE(r_write_wavefield); SCOREP_USER_REGION_BEGIN(r_write_wavefield, "checkpoint_write_wavefield", SCOREP_USER_REGION_TYPE_COMMON); checkErr(sion_coll_fwrite(dofs(), sizeof(real), numDofs(), file), numDofs()); SCOREP_USER_REGION_END(r_write_wavefield); // Finalize the checkpoint finalizeCheckpoint(file); logInfo(rank()) << "Checkpoint backend: Writing. Done."; }
OSStatus CAPlayThrough::Init(AudioDeviceID input, AudioDeviceID output) { OSStatus err = noErr; //Note: You can interface to input and output devices with "output" audio units. //Please keep in mind that you are only allowed to have one output audio unit per graph (AUGraph). //As you will see, this sample code splits up the two output units. The "output" unit that will //be used for device input will not be contained in a AUGraph, while the "output" unit that will //interface the default output device will be in a graph. //Setup AUHAL for an input device err = SetupAUHAL(input); checkErr(err); //Setup Graph containing Varispeed Unit & Default Output Unit err = SetupGraph(output); checkErr(err); err = SetupBuffers(); checkErr(err); // the varispeed unit should only be conected after the input and output formats have been set err = AUGraphConnectNodeInput(mGraph, mVarispeedNode, 0, mOutputNode, 0); checkErr(err); err = AUGraphInitialize(mGraph); checkErr(err); //Add latency between the two devices ComputeThruOffset(); return err; }
void printDeviceName( size_t dev_id, cl_device_id device ) { int i = 0; cl_int err = CL_SUCCESS; cl_device_type devType; char pbuf[100]; printf( "DEVICE[%d]: ", dev_id ); err = clGetDeviceInfo( device, CL_DEVICE_TYPE, sizeof(devType), &devType, NULL ); checkErr( "clGetDeviceInfo", err ); switch( devType ) { case CL_DEVICE_TYPE_CPU: printf( "CL_DEVICE_TYPE_CPU, " ); break; case CL_DEVICE_TYPE_GPU: printf( "CL_DEVICE_TYPE_GPU, " ); break; default: printf( "Unknown device type %d, ", devType ); break; } err = clGetDeviceInfo( device, CL_DEVICE_NAME, sizeof(pbuf), pbuf, NULL ); checkErr( "clGetDeviceINfo", err ); printf( "Name=%s\n", pbuf ); }
void seissol::checkpoint::posix::Wavefield::load(double &time, int ×tepWaveField, real* dofs) { logInfo(rank()) << "Loading wave field checkpoint"; seissol::checkpoint::CheckPoint::setLoaded(); int file = open(); checkErr(file); // Read header WavefieldHeader header; readHeader(file, header); time = header.time; timestepWaveField = header.timestepWaveField; // Skip other processes before this in the group checkErr(lseek64(file, groupOffset() * sizeof(real), SEEK_CUR)); // Convert to char* to do pointer arithmetic char* buffer = reinterpret_cast<char*>(dofs); unsigned long left = numDofs()*sizeof(real); // Read dofs while (left > 0) { unsigned long readSize = read(file, buffer, left); if (readSize <= 0) checkErr(readSize, left); buffer += readSize; left -= readSize; } // Close the file checkErr(::close(file)); }
CLMandel() { cl_int err; std::vector< cl::Platform > platformList; cl::Platform::get(&platformList); checkErr(platformList.size()!=0 ? CL_SUCCESS : -1, "cl::Platform::get"); std::cerr << "Platform number is: " << platformList.size() << std::endl; std::string platformVendor; for(unsigned i = 0; i < platformList.size(); ++i) { platformList[i].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor); std::cerr << "Platform is by: " << platformVendor << "\n"; } cl_context_properties cprops[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[oclplatform])(), 0}; m_context = cl::Context ( CL_DEVICE_TYPE_ALL, cprops, NULL, NULL, &err); checkErr(err, "Conext::Context()"); std::vector<cl::Device> devices; devices = m_context.getInfo<CL_CONTEXT_DEVICES>(); checkErr(devices.size() > 0 ? CL_SUCCESS : -1, "devices.size() > 0"); for(unsigned i = 0; i < devices.size(); ++i) { cl_int deviceType = devices[i].getInfo<CL_DEVICE_TYPE>(); std::cerr << "Device " << i << ": "; if(deviceType & CL_DEVICE_TYPE_CPU) std::cerr << "CL_DEVICE_TYPE_CPU "; if(deviceType & CL_DEVICE_TYPE_GPU) std::cerr << "CL_DEVICE_TYPE_GPU "; if(deviceType & CL_DEVICE_TYPE_ACCELERATOR) std::cerr << "CL_DEVICE_TYPE_ACCELERATOR "; if(deviceType & CL_DEVICE_TYPE_DEFAULT) std::cerr << "CL_DEVICE_TYPE_DEFAULT "; std::cerr << std::endl; } m_device = devices[0]; m_cmdq = cl::CommandQueue(m_context, m_device, 0, &err); checkErr(err, "CommandQueue::CommandQueue()"); std::ifstream file("mandel.cl"); std::string prog((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); cl::Program::Sources source(1, std::make_pair(prog.c_str(), prog.length()+1)); cl::Program program(m_context, source); err = program.build(devices,""); m_kernel = cl::Kernel(program, "mandel", &err); checkErr(err, "Kernel::Kernel()"); }
OSStatus CAPlayThrough::SetInputDeviceAsCurrent(AudioDeviceID in) { UInt32 size = sizeof(AudioDeviceID); OSStatus err = noErr; if(in == kAudioDeviceUnknown) //get the default input device if device is unknown { err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &size, &in); checkErr(err); } mInputDevice.Init(in, true); //Set the Current Device to the AUHAL. //this should be done only after IO has been enabled on the AUHAL. err = AudioUnitSetProperty(mInputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mInputDevice.mID, sizeof(mInputDevice.mID)); checkErr(err); return err; }
void PlaceDatabase::prepareReusedStatements() { // Prepared statement for inserting some data static const char INSERT_SQL[] = "INSERT INTO places VALUES " "($id, $stamp," " $map_pos_x, $map_pos_y, $map_pos_z, $map_ori_x, $map_ori_y, $map_ori_z, $map_ori_w," " $opt_pos_x, $opt_pos_y, $opt_pos_z, $opt_ori_x, $opt_ori_y, $opt_ori_z, $opt_ori_w," " $fx, $fy, $cx, $cy, $tx, $disps, $good_pts," " $num_pts, $keypts, $desc_len, $desc_data, $document, $left, $right)"; checkErr(sqlite3_prepare_v2(persistent_db_, INSERT_SQL, sizeof(INSERT_SQL), &insert_stmt_, NULL), "Couldn't prepare INSERT statement"); map_pose_param_index_ = sqlite3_bind_parameter_index(insert_stmt_, "$map_pos_x"); optical_transform_param_index_ = sqlite3_bind_parameter_index(insert_stmt_, "$opt_pos_x"); camera_param_index_ = sqlite3_bind_parameter_index(insert_stmt_, "$fx"); disparities_param_index_ = sqlite3_bind_parameter_index(insert_stmt_, "$disps"); keypoints_param_index_ = sqlite3_bind_parameter_index(insert_stmt_, "$num_pts"); assert(map_pose_param_index_ != 0); assert(optical_transform_param_index_ != 0); assert(camera_param_index_ != 0); assert(disparities_param_index_ != 0); assert(keypoints_param_index_ != 0); // Prepared statement for getting transform data for a particular place static const char SELECT_TRANSFORMS_SQL[] = "SELECT map_position_x, map_position_y, map_position_z," " map_orientation_x, map_orientation_y, map_orientation_z, map_orientation_w," " optical_position_x, optical_position_y, optical_position_z," " optical_orientation_x, optical_orientation_y, optical_orientation_z, optical_orientation_w " "FROM places WHERE id = ?"; checkErr(sqlite3_prepare_v2(persistent_db_, SELECT_TRANSFORMS_SQL, sizeof(SELECT_TRANSFORMS_SQL), &select_transforms_stmt_, NULL), "Couldn't prepare SELECT transforms statement"); // Prepared statement for getting frame data for a particular place static const char SELECT_FRAME_SQL[] = "SELECT cam_fx, cam_fy, cam_cx, cam_cy, cam_tx, disparities, good_points," " num_keypoints, keypoints, descriptor_length, descriptor_data " "FROM places WHERE id = ?"; checkErr(sqlite3_prepare_v2(persistent_db_, SELECT_FRAME_SQL, sizeof(SELECT_FRAME_SQL), &select_frame_stmt_, NULL), "Couldn't prepare SELECT frame statement"); // Prepared statement for spatial queries static const char SELECT_SPATIAL_SQL[] = "SELECT id FROM places WHERE map_position_x BETWEEN $min_x AND $max_x AND" " map_position_y BETWEEN $min_y AND $max_y" " ORDER BY id"; checkErr(sqlite3_prepare_v2(persistent_db_, SELECT_SPATIAL_SQL, sizeof(SELECT_SPATIAL_SQL), &select_spatial_stmt_, NULL), "Couldn't prepare SELECT spatial statement"); static const char SELECT_IMAGES_SQL[] = "SELECT left_image, right_image FROM places WHERE id = ?"; checkErr(sqlite3_prepare_v2(persistent_db_, SELECT_IMAGES_SQL, sizeof(SELECT_IMAGES_SQL), &select_images_stmt_, NULL), "Couldn't prepare SELECT images statement"); }
void Layer::getResults(NeuralCL& c, float* f){ cl_int ret; ret=clWaitForEvents(1, &layer_last_event); checkErr(ret, "Layer::getResults: Failed to read buffer"); ret = clEnqueueReadBuffer(c.command_queue, results_id, CL_TRUE, 0, N*sizeof(float), f, 0, NULL, NULL); checkErr(ret, "Layer::getResults: Failed to read buffer"); }
void PlaceDatabase::bindCameraParams(const frame_common::CamParams& cam) { int idx = camera_param_index_; checkErr(sqlite3_bind_double(insert_stmt_, idx + 0, cam.fx), "Bind error"); checkErr(sqlite3_bind_double(insert_stmt_, idx + 1, cam.fy), "Bind error"); checkErr(sqlite3_bind_double(insert_stmt_, idx + 2, cam.cx), "Bind error"); checkErr(sqlite3_bind_double(insert_stmt_, idx + 3, cam.cy), "Bind error"); checkErr(sqlite3_bind_double(insert_stmt_, idx + 4, cam.tx), "Bind error"); }
void PlaceDatabase::getTransforms(int64_t id, tf::Pose& pose_in_map, tf::Transform& optical_transform) const { checkErr(sqlite3_bind_int64(select_transforms_stmt_, 1, id), "Couldn't bind row id"); checkErr(sqlite3_step(select_transforms_stmt_), "SELECT transforms didn't return data", SQLITE_ROW); extractTransform(pose_in_map, 0); extractTransform(optical_transform, 7); checkErr(sqlite3_step(select_transforms_stmt_), "SELECT transforms returned more than one row", SQLITE_DONE); checkErr(sqlite3_reset(select_transforms_stmt_), "Couldn't reset SELECT transforms statement"); }
void seissol::checkpoint::posix::Wavefield::write(double time, int timestepWaveField) { EPIK_TRACER("CheckPoint_write"); SCOREP_USER_REGION("CheckPoint_write", SCOREP_USER_REGION_TYPE_FUNCTION); logInfo(rank()) << "Checkpoint backend: Writing."; // Start at the beginning checkErr(lseek64(file(), 0, SEEK_SET)); // Write the header EPIK_USER_REG(r_write_header, "checkpoint_write_header"); SCOREP_USER_REGION_DEFINE(r_write_header); EPIK_USER_START(r_write_header); SCOREP_USER_REGION_BEGIN(r_write_header, "checkpoint_write_header", SCOREP_USER_REGION_TYPE_COMMON); WavefieldHeader header; header.time = time; header.timestepWaveField = timestepWaveField; writeHeader(file(), header); EPIK_USER_END(r_write_header); SCOREP_USER_REGION_END(r_write_header); // Save data EPIK_USER_REG(r_write_wavefield, "checkpoint_write_wavefield"); SCOREP_USER_REGION_DEFINE(r_write_wavefield); EPIK_USER_START(r_write_wavefield); SCOREP_USER_REGION_BEGIN(r_write_wavefield, "checkpoint_write_wavefield", SCOREP_USER_REGION_TYPE_COMMON); // Convert to char* to do pointer arithmetic const char* buffer = reinterpret_cast<const char*>(dofs()); unsigned long left = numDofs()*sizeof(real); if (alignment()) { left = (left + alignment() - 1) / alignment(); left *= alignment(); } while (left > 0) { unsigned long written = ::write(file(), buffer, left); if (written <= 0) checkErr(written, left); buffer += written; left -= written; } EPIK_USER_END(r_write_wavefield); SCOREP_USER_REGION_END(r_write_wavefield); // Finalize the checkpoint finalizeCheckpoint(); logInfo(rank()) << "Checkpoint backend: Writing. Done."; }
void PlaceDatabase::getImages(int64_t id, cv::Mat& left, cv::Mat& right) { checkErr(sqlite3_bind_int64(select_images_stmt_, 1, id), "Couldn't bind row id"); checkErr(sqlite3_step(select_images_stmt_), "SELECT images didn't return data", SQLITE_ROW); extractImage(left, 0); extractImage(right, 1); checkErr(sqlite3_step(select_images_stmt_), "SELECT images returned more than one row", SQLITE_DONE); checkErr(sqlite3_reset(select_images_stmt_), "Couldn't reset SELECT images statement"); }
OSStatus CAPlayThrough::SetupAUHAL(AudioDeviceID in) { OSStatus err = noErr; AudioComponent comp; AudioComponentDescription desc; //There are several different types of Audio Units. //Some audio units serve as Outputs, Mixers, or DSP //units. See AUComponent.h for listing desc.componentType = kAudioUnitType_Output; //Every Component has a subType, which will give a clearer picture //of what this components function will be. desc.componentSubType = kAudioUnitSubType_HALOutput; //all Audio Units in AUComponent.h must use //"kAudioUnitManufacturer_Apple" as the Manufacturer desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentFlags = 0; desc.componentFlagsMask = 0; //Finds a component that meets the desc spec's comp = AudioComponentFindNext(NULL, &desc); if (comp == NULL) exit (-1); //gains access to the services provided by the component err = AudioComponentInstanceNew(comp, &mInputUnit); checkErr(err); //AUHAL needs to be initialized before anything is done to it err = AudioUnitInitialize(mInputUnit); checkErr(err); err = EnableIO(); checkErr(err); err= SetInputDeviceAsCurrent(in); checkErr(err); err = CallbackSetup(); checkErr(err); //Don't setup buffers until you know what the //input and output device audio streams look like. err = AudioUnitInitialize(mInputUnit); return err; }
void Layer::evaluate(NeuralCL& c){ if(input)return; assert(prevLayer); assert(results_id); prevLayer->evaluate(c); printf("Setting eval kernel arguments...\n"); //get previous layer's N cl_uint M=prevLayer->N; cl_int ret; //set arguments ret = clSetKernelArg(c.kernels[KERNEL_EVALUATE], 0, sizeof(cl_mem), (void *)&prevLayer->results_id); checkErr(ret, "Failed to set c.kernel arguments 0\n"); ret = clSetKernelArg(c.kernels[KERNEL_EVALUATE], 1, sizeof(cl_mem), (void *)&weights_id); checkErr(ret, "Failed to set c.kernel arguments 1\n"); ret = clSetKernelArg(c.kernels[KERNEL_EVALUATE], 2, sizeof(cl_mem), (void *)&results_id); checkErr(ret, "Failed to set c.kernel arguments 2\n"); ret = clSetKernelArg(c.kernels[KERNEL_EVALUATE], 3, sizeof(cl_uint), (void *)&M); checkErr(ret, "Failed to set c.kernel arguments 3\n"); printf("Set eval kernel arguments.\n"); printf("Running kernel...\n"); size_t offsets[]={0}; size_t sizes[]={(size_t)N}; size_t local_sizes[]={1}; bool p=(prevLayer->input); if(p){ ret=clEnqueueNDRangeKernel(c.command_queue, c.kernels[KERNEL_EVALUATE], //what kernel 1, offsets, sizes, local_sizes, 0, 0, &layer_last_event); }else{ cl_event* e=&(prevLayer->layer_last_event); ret=clEnqueueNDRangeKernel(c.command_queue, c.kernels[KERNEL_EVALUATE], //what kernel 1, offsets, sizes, local_sizes, 1, e, &layer_last_event);//the events } checkErr(ret, "Failed to run kernel\n"); printf("Ran kernel.\n"); }
int GameApp::setupSound() { FMOD_RESULT result; result = FMOD::System_Create(&system); // Create the main system object. checkErr(result, std::string("FMOD error! ") + std::string(FMOD_ErrorString(result))); result = system->setSoftwareChannels(100); // Allow 100 software mixed voices to be audible at once. checkErr(result, std::string("FMOD error! ") + std::string(FMOD_ErrorString(result))); result = system->init(100, FMOD_INIT_NORMAL, 0); // Initialize FMOD. checkErr(result, std::string("FMOD error! ") + std::string(FMOD_ErrorString(result))); return result; }
void Layer::cleanup(NeuralCL& c){ cl_int ret; /* Clean Up Memory Object */ if(!input){ ret = clReleaseMemObject(weights_id); checkErr(ret, "Failed to enqueue release buffer\n"); } ret = clReleaseMemObject(results_id); checkErr(ret, "Failed to enqueue release buffer\n"); weights_id=0; results_id=0; printf("Cleaned up layer.\n"); if(!input) prevLayer->cleanup(c); }
void seissol::checkpoint::posix::Wavefield::write(double time, int timestepWaveField) { EPIK_TRACER("CheckPoint_write"); SCOREP_USER_REGION("CheckPoint_write", SCOREP_USER_REGION_TYPE_FUNCTION); logInfo(rank()) << "Writing check point."; // Skip identifier checkErr(lseek64(file(), sizeof(unsigned long), SEEK_SET)); // Write the header EPIK_USER_REG(r_write_header, "checkpoint_write_header"); SCOREP_USER_REGION_DEFINE(r_write_header); EPIK_USER_START(r_write_header); SCOREP_USER_REGION_BEGIN(r_write_header, "checkpoint_write_header", SCOREP_USER_REGION_TYPE_COMMON); checkErr(::write(file(), &time, sizeof(time)), sizeof(time)); checkErr(::write(file(), ×tepWaveField, sizeof(timestepWaveField)), sizeof(timestepWaveField)); EPIK_USER_END(r_write_header); SCOREP_USER_REGION_END(r_write_header); // Save data EPIK_USER_REG(r_write_wavefield, "checkpoint_write_wavefield"); SCOREP_USER_REGION_DEFINE(r_write_wavefield); EPIK_USER_START(r_write_wavefield); SCOREP_USER_REGION_BEGIN(r_write_wavefield, "checkpoint_write_wavefield", SCOREP_USER_REGION_TYPE_COMMON); // Convert to char* to do pointer arithmetic const char* buffer = reinterpret_cast<const char*>(dofs()); unsigned long left = numDofs()*sizeof(real); while (left > 0) { unsigned long written = ::write(file(), buffer, left); if (written <= 0) checkErr(written, left); buffer += written; left -= written; } EPIK_USER_END(r_write_wavefield); SCOREP_USER_REGION_END(r_write_wavefield); // Finalize the checkpoint finalizeCheckpoint(); logInfo(rank()) << "Writing check point. Done."; }
/* * show what options the user has for fields for display and filtering */ static err_code listOptions( void) { int i, j; checkErr((!isROA) && (!isCRL) && (!isCert) && (!isManifest) && (!isGBR), BAD_OBJECT_TYPE); printf("\nPossible fields to display or use in clauses for a %s:\n", objectType); for (i = 0; i < getNumFields(); i++) { if (getFields()[i].description == NULL) continue; if (((getFields()[i].flags & Q_FOR_ROA) && isROA) || ((getFields()[i].flags & Q_FOR_CRL) && isCRL) || ((getFields()[i].flags & Q_FOR_CERT) && isCert) || ((getFields()[i].flags & Q_FOR_MAN) && isManifest) || ((getFields()[i].flags & Q_FOR_GBR) && isGBR)) { printf(" %s: %s\n", getFields()[i].name, getFields()[i].description); if (getFields()[i].flags & Q_JUST_DISPLAY) { for (j = 0; j < (int)strlen(getFields()[i].name) + 4; j++) printf(" "); printf("(Note: This can be used only for display.)\n"); } } } printf("\n"); return 0; }
OSStatus CAPlayThrough::Stop() { OSStatus err = noErr; if(IsRunning()){ //Stop the AUHAL err = AudioOutputUnitStop(mInputUnit); checkErr(err); err = AUGraphStop(mGraph); checkErr(err); mFirstInputTime = -1; mFirstOutputTime = -1; } return err; }
void Layer::readNeuronArray(NeuralCL& c, int ind, float* array){ assert(ind>=0&&ind<=N); cl_int ret; ret = clEnqueueReadBuffer(c.command_queue, weights_id, CL_TRUE, 0, N*sizeof(float), array+ind*prevLayer->N, 0, NULL, NULL); checkErr(ret, "Layer::getResults: Failed to read buffer"); }
/* * Load program source based on filename. * * filename - the file to load the source from * context - TODO - why does clCreateProgramWIthSource need this? * * return - the cl_program that was created */ cl_program RiverModelCL::loadProgram(string filename) { cl_int error; std::ifstream kernelFile(filename.c_str(), std::ios::in); if(!kernelFile.is_open()) { cerr << "Failed to open kernel file for reading!" << endl; clReleaseContext(context); return NULL; } std::ostringstream oss; oss << kernelFile.rdbuf(); std::string srcStr = oss.str(); // Load source to cl_program cout << "Loading program source" << endl; cl_program program = clCreateProgramWithSource(context, 1, (const char**)&srcStr, NULL, &error); checkErr(error, "Error loading program source!", true); if(error != CL_SUCCESS) { return NULL; } else { return program; } }
OSStatus CAPlayThrough::SetOutputDeviceAsCurrent(AudioDeviceID out) { UInt32 size = sizeof(AudioDeviceID);; OSStatus err = noErr; // UInt32 propsize = sizeof(Float32); //AudioObjectPropertyScope theScope = mIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; if(out == kAudioDeviceUnknown) //Retrieve the default output device { err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &out); checkErr(err); } mOutputDevice.Init(out, false); //Set the Current Device to the Default Output Unit. err = AudioUnitSetProperty(mOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mOutputDevice.mID, sizeof(mOutputDevice.mID)); return err; }
OSStatus CAPlayThrough::InputProc(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData) { OSStatus err = noErr; CAPlayThrough *This = (CAPlayThrough *)inRefCon; if (This->mFirstInputTime < 0.) This->mFirstInputTime = inTimeStamp->mSampleTime; //Get the new audio data err = AudioUnitRender(This->mInputUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, //# of frames requested This->mInputBuffer);// Audio Buffer List to hold data checkErr(err); if(!err) err = This->mBuffer->Store(This->mInputBuffer, Float64(inNumberFrames), SInt64(inTimeStamp->mSampleTime)); return err; }
OSStatus CAPlayThrough::EnableIO() { OSStatus err = noErr; UInt32 enableIO; /////////////// //ENABLE IO (INPUT) //You must enable the Audio Unit (AUHAL) for input and disable output //BEFORE setting the AUHAL's current device. //Enable input on the AUHAL enableIO = 1; err = AudioUnitSetProperty(mInputUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, // input element &enableIO, sizeof(enableIO)); checkErr(err); //disable Output on the AUHAL enableIO = 0; err = AudioUnitSetProperty(mInputUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, //output element &enableIO, sizeof(enableIO)); return err; }
/*! @function wavread @abstract Read an audio file into memory. @discussion An utility function that reads the contents of an audio file into a SIGNAL structure. It uses and depends on the libsndfile API. @param INPUTFILENAME The filename to use for the input file. If no path is provided the file will be read from the location of the executable. @param INPUT A SIGNAL structure containing the audio data read from the audio file. @result SfError a libsndfile error code (an integer). */ SfError wavread(const char* inputFileName, SIGNAL *input) { int err=0; SNDFILE *file=NULL; SF_INFO info; sf_count_t framesread=0; info.format=0; //Open a file for reading. if(!(file=sf_open(inputFileName, SFM_READ, &info))) { printf("Failed to open '%s' for reading!\n",inputFileName); err=sf_error(file); checkErr(err,kSndFileSystem,"wavread: opening file"); return err; //Return at this point because the file did not open, so there is nothing we can do! } //Check if SF_INFO struct is valid //err=sf_format_check(&info); //checkErr(err,kSndFileSystem,"wavread: format checking code"); //Create a buffer to hold audio data. float *buffer=(float *)malloc(sizeof(float)* info.frames*info.channels); //Read audio data into buffer; framesread=sf_readf_float(file, buffer, info.frames); if(framesread==0) printf("No frames were read from the file! The file is either corrupt or the operation failed!\n"); err=sf_error(file); checkErr(err,kSndFileSystem,"wavread: reading audio data into buffer"); //Close audio file. err=sf_close(file); checkErr(err,kSndFileSystem,"wavread: closing file"); //Set up SIGNAL structure based on aqquired SF_INFO input->name=inputFileName; //Name of the input signal procided by the user input->frames=info.frames; //Number of frames of the audio file input->samplerate=info.samplerate; //Sample rate of audio file input->channels=info.channels; //Number of channels of audio file input->format=info.format; //Format of audio file input->sections=info.sections; //Sections of audio file input->seekable=info.seekable; //One ('1') if audio file is seekable, zero otherwise input->data=buffer; //The buffer that contains the actual audio data/samples of the audio file return err; }
cl_int _clGetPlatformInfo(cl_platform_id platform,cl_platform_info param_name, size_t param_value_size, void *param_value,size_t *param_value_size_ret) { cl_int err; err = clGetPlatformInfo(platform,param_name,param_value_size,param_value,param_value_size_ret); checkErr("clGetPlatformInfo",err); return err; }
cl_int _clReleaseProgram(cl_program program) { cl_int err; err = clReleaseProgram(program); checkErr("clReleaseProgram",err); return err; }
cl_int _clUnloadCompiler(void) { cl_int err; err = clUnloadCompiler(); checkErr("clUnloadCompiler",err); return err; }