bool X11Audio::init(char * p_hostname, uint2 p_channels, uint2 p_width) { if ( !isinit() ) { MCuseESD = ( initialise_weak_link_esd() != 0 ) ; if ( p_hostname != NULL ) m_host = p_hostname ; m_flags = 0 ; if ( p_channels == 1 ) m_flags |= ESD_MONO ; else m_flags |= ESD_STEREO ; if ( p_width == 1 ) m_flags |= ESD_BITS8 ; else m_flags |= ESD_BITS16 ; // m_esd_connection is no longer used to specify the network sound channel. // we still use it as a little flag to say we are all set-up and ready to go. m_esd_connection = 1; return true ; } return true ; }
void X11Audio::close(void) { if ( isinit() ) { esd_close(m_esd_connection); } }
int X11Audio::play(int1 * p_sample, uint4 p_samplesize, uint p_rate) { if ( isinit() ) { uint t_func = ESD_PLAY | ESD_STREAM | m_flags; int chan ; chan = esd_play_stream(t_func, p_rate, NULL, NULL); uint t_bytes_written ; t_bytes_written = write(chan, p_sample, p_samplesize); esd_close(chan); return t_bytes_written ; } }
elemptr symmodel::get_model_widx( const vector<string>& parsed, const vector<size_t>& idx, const vector<elemptr>& trace ) { //I start with it already parsed. //If parsed.size() == 0, I simply return this (with an index?) //The empty string indicates "this" model? No, when I parse it, I need to sep it, so an empty, will return in a zero-parse, of size zero, or nothing? //Either way, would result in same, so return ;) if( parsed.size() == 0 || parsed[0].compare("") == 0 ) { fprintf(stdout, "FOUND MODEL! [%s]\n", buildpath().c_str() ); elemptr t = elemptr( shared_from_this(), idx ); return t; } else { fprintf(stdout, "Model [%s], attempting to find model name [%s] widx (note, trace size is [%lu])\n", buildpath().c_str(), CAT(parsed, "/").c_str(), trace.size()); } //This is the next model I will go into string submodel = parsed[0]; vector<string> remainder( parsed.begin()+1, parsed.end() ); //same as remainder, remainder.erase(0); //REV: This is where I should iterate up the tree! This is the issue. vector<size_t> mlocs = find_model( submodel ); vector<size_t> hlocs = find_hole( submodel ); //At this point, we are finding the hole etc. normally. if( mlocs.size() >= 1 ) { if( mlocs.size() > 1 ) { fprintf(stderr, "WTF found more than one in getmodelwidx\n"); exit(1); } size_t mloc = mlocs[0]; //add model to trace? I guess? It is a submodel, so it is not necessary I guess? But it helps it find submodels I guess? Could this cause a problem? fprintf(stdout, "Model [%s], going through submodel [%s] to find [%s]\n", buildpath().c_str(), models[mloc]->localname.c_str(), CAT(remainder, "/").c_str() ); std::shared_ptr<symmodel> nextmodel = models[mloc]; //Don't add to trace because if same model, parent will cause infinite loop in combin with trace. //However //Problem is if I go through a hole, and the hole is the same model, that is the main problem vector<elemptr> newtrace = trace; //size_t idx_in_submodel = idx; //no change, b/c submodel. vector<size_t> idx_in_submodel = idx; //no change, b/c submodel. //newtrace.push_back( elemptr( shared_from_this(), idx ) ); return nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace ); } else if( hlocs.size() >= 1 ) { if( hlocs.size() > 1) { fprintf(stderr, "WTF more than one HOLE found in getmodelwidx\n"); exit(1); } size_t hloc = hlocs[0]; fprintf(stdout, "Model [%s], going through hole [%s] to find [%s]\n", buildpath().c_str(), holes[hloc].name.c_str(), CAT(remainder, "/").c_str()); if( holes[ hloc ].members.size() != 1 ) { fprintf(stderr, "ERROR in get_model_widx, getting [%s] from HOLE, but hole [%s] has size [%lu], but it should be 1\n", submodel.c_str(), holes[hloc].name.c_str(), holes[hloc].members.size() ); exit(1); } //REV: so in the case it does not exist yet, we have a problem? std::shared_ptr<symmodel> nextmodel = holes[hloc].members[0]; if( check_same_toplevel_model( nextmodel ) ) { //Dont add to trace because its same model so infinite loop with going to parent.x vector<elemptr> newtrace = trace; //size_t idx_in_submodel = idx; //no change, b/c submodel. vector<size_t> idx_in_submodel = idx; //no change, b/c submodel. //newtrace.push_back( elemptr( shared_from_this(), idx ) ); return nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace ); } else //not same toplevel model { //I NEED TO GO THROUGH A CORRESPONDENCE fprintf(stdout, "REV: about to go through a corresp to get a non-same model thing through a hole...\n"); //std::shared_ptr<corresp> mycorresp; auto mycorresp = getcorresp( nextmodel ); if( !mycorresp ) { fprintf(stderr, "REV: getcorresp in get_model_widx, failed, no such corresp exists between [%s] and [%s]\n", buildpath().c_str(), nextmodel->buildpath().c_str()); exit(1); } //REV; SANITY, if corresp not allocated yet, just return 0. //size_t idx_in_submodel = 0; vector<size_t> idx_in_submodel(1,0); //REV; Don't check this here, check this in the corresp struct? I.e. return dummy data if it is not existing yet (or exit?) if(mycorresp->isinit()) { fprintf(stdout, "Corresp is INIT!!!! Will attempt a GETALL...\n"); //REV: TODO HERE, just return it directly, with new IDX_IN_SUBMODEL ;0 //REV: this is it!!! This is where I vector<size_t> sanity = mycorresp->getall( idx ); fprintf(stdout, "Attempted to GETALL from the corresp!\n"); /*if( sanity.size() != 1 ) { fprintf(stderr, "SANITY check for corresp during access failed! Expected corresp for idx [%lu] of model [%s] to have only 1 corresponding element in model [%s], but it had [%lu]\n", idx, buildpath().c_str(), nextmodel->buildpath().c_str(), sanity.size() ); exit(1); } size_t idx_in_submodel = sanity[0]; //no change, b/c submodel. */ idx_in_submodel = sanity; } vector<elemptr> newtrace = trace; newtrace.push_back( elemptr( shared_from_this(), idx ) ); fprintf(stdout, "About to get next model with idx...\n"); auto toret = nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace ); fprintf(stdout, "FINISHED About to get next model with idx...\n"); return toret; } } //end if not found in HOLES (or submodels) else { fprintf(stdout, "Model [%s], walking up to parent [%s] to find [%s]\n", buildpath().c_str(), parent->localname.c_str(), CAT(parsed, "/").c_str()); //Else, try to bubble up to ROOT. if( parent && (parent->parent) ) { std::shared_ptr<symmodel> nextmodel = parent; vector<elemptr> newtrace = trace; //size_t idx_in_submodel = idx; //no change, b/c submodel. vector<size_t> idx_in_submodel = idx; //no change, b/c submodel. //newtrace.push_back( elemptr( shared_from_this(), idx ) ); return nextmodel->get_model_widx( parsed, idx_in_submodel, newtrace ); } else if( parent && !(parent->parent) ) { //Couldn't find it! Return empty elemptr...bad. elemptr ep; return ep; } else { fprintf(stderr, "REV; this should never happen weird, Neither parent nor parent->parent? In searching for model with idx. Exit\n"); if( parent ) { fprintf( stderr, "Parent of me [%s] exists and is [%s]\n", buildpath().c_str(), parent->buildpath().c_str() ); } else { fprintf( stderr, "Parent does not exist... (note current model is [%s])!\n", buildpath().c_str() ); } exit(1); } } //couldn't find in "else" (i.e. not in this model, so try bubbling up parents) if(trace.size() == 0) { fprintf(stderr, "Trace size zero. This should never happen (should have been caught above)\n"); exit(1); } //REV: Did I mess something up? First it should check through all guys directly to see if it is same model? I.e. if target model matches b/c we can use that idx. fprintf(stdout, "Couldn't find model [%s] in previous model trace [%s], so moving to next! (trace size is [%lu])\n", CAT(parsed,"/").c_str(), buildpath().c_str(), trace.size() ); //Move back model and try again? vector<elemptr> newtrace = trace; //size_t idx_in_submodel = newtrace[ newtrace.size() - 1].idx; //end of trace. vector<size_t> idx_in_submodel = newtrace[ newtrace.size() - 1].idx; //end of trace. std::shared_ptr<symmodel> nextmodel = newtrace[ newtrace.size() - 1].model; newtrace.pop_back(); fprintf(stdout, "Will now try to run with new trace size [%lu]\n", newtrace.size() ); return nextmodel->get_model_widx( parsed, idx_in_submodel, newtrace ); } //end get_model_widx