static void closeAudioFile() { GOC_DEBUG("-> closeAudioFile"); filename = NULL; decoderClose(); playerCloseOutput(); GOC_DEBUG("<- closeAudioFile"); }
void endProgram(int ret) { params = freeParameters(params); GOC_DEBUG("Closing libao Device\n"); closeOutputDevice(); GOC_DEBUG("Closing libao\n"); ao_shutdown(); // goc_termRestore(); exit(ret); }
static enum MixerCode alsaMixerSelectCard(struct MixerSystem* system, int mixerId) { enum MixerCode code; snd_mixer_elem_t* mixerElem = NULL; AlsaMixerCard* card = (AlsaMixerCard*)system->active; if ( !card ) { if ( card == system->mixerCard->pElement[mixerId] ) { return MIXER_CODE_OK; } alsaMixerCardClose(system); } code = commonMixerSelectCard(system, mixerId); if ( code != MIXER_CODE_OK ) { GOC_DEBUG("Cannot select card by commonMixerSelectCard"); return code; } card = (AlsaMixerCard*)system->active; GOC_CHEOP_DEBUG(snd_mixer_open( &card->sndmixer, 0 ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_attach( card->sndmixer, card->physicalName ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_selem_register( card->sndmixer, NULL, NULL ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_load( card->sndmixer ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); mixerElem = snd_mixer_first_elem( card->sndmixer ); while ( mixerElem ) { AlsaMixerElement* pMixerElement = alsaMixerElementAlloc(); for (int channel = 0; channel <= SND_MIXER_SCHN_LAST; channel++ ) { if ( snd_mixer_selem_has_playback_channel(mixerElem, channel) && snd_mixer_selem_get_playback_volume_range(mixerElem, &pMixerElement->rangemin, &pMixerElement->rangemax) == 0 && snd_mixer_selem_get_playback_volume(mixerElem, channel, &pMixerElement->volume) == 0 ) { pMixerElement->name = goc_stringCopy(NULL, snd_mixer_selem_get_name(mixerElem)); pMixerElement->type = MIXER_ELEMENT_PLAYBACK; pMixerElement->sndelement = mixerElem; card->mixerElement = goc_arrayAdd( card->mixerElement, pMixerElement ); break; } else if ( snd_mixer_selem_has_capture_channel(mixerElem, channel) && snd_mixer_selem_get_capture_volume_range(mixerElem, &pMixerElement->rangemin, &pMixerElement->rangemax) == 0 && snd_mixer_selem_get_capture_volume(mixerElem, channel, &pMixerElement->volume) == 0 ) { pMixerElement->name = goc_stringCopy(NULL, snd_mixer_selem_get_name(mixerElem)); pMixerElement->type = MIXER_ELEMENT_CAPTURE; pMixerElement->sndelement = mixerElem; card->mixerElement = goc_arrayAdd( card->mixerElement, pMixerElement ); break; } } mixerElem = snd_mixer_elem_next( mixerElem ); } return MIXER_CODE_OK; }
int main(int argc, char** argv) { // zak³ada siê, ¿e ramka zawiera próbkê, w której // jest d¼wiêk beat-u i cisza do nastêpnego beatu // // // ramka //char *pFrame; // licznik int i; // goc_termInit(); printf(GOC_STRING_WHITE); // Procedury inicjuj±ce GOC_DEBUG("Initializing libao"); ao_initialize(); GOC_DEBUG("Initializing libao Device"); aodriverid = ao_default_driver_id(); if ( aodriverid == -1 ) return -1; openOutputDevice(); params = allocParameters(); if ( argc > 1 ) { if ( interpretArgs(argc, argv, params) < 0 ) endProgram(-1); } GOC_DEBUG("Allocating buffer"); generateBeat(params, BEAT_BASE); generateBeat(params, BEAT_ACCENT); generateBeat(params, BEAT_INTER); generateBeat(params, BEAT_QUIET); // pFrame = malloc(nFrame); // memset(pFrame, 0, nFrame); GOC_BINFO("Tempo: %d Rate: %d Channels: %d Bits: %d", params->tempo, SAMPLE_RATE, SAMPLE_CHANNELS, SAMPLE_BITS); // GOC_BDEBUG("Allocated %d at 0x%X", nFrame, (unsigned int)pFrame); if ( params->flags & FLAG_PRINTCOUNT ) { goc_clearscreen(); goc_gotoxy(1,1); } printf("Playing ... \n"); if ( params->pattern ) printf("Use pattern: %s\n", params->pattern); fflush(stdout); { // to nie do koñca jest liczba ramek - to jest liczba // podstawowych beatów jakie maj± zostaæ zagrane - nie // s± liczone beat-y po¶rednie int nFrames; int imeasure = 0; int iinter; int patternPosition = 0; int patternLen = 0; char *prevString = goc_stringCopy(NULL, ""); char playedPattern = '.'; if ( params->pattern ) { patternLen = strlen(params->pattern); } if ( params->tacts ) // na podstawie liczby podanych taktów nFrames = params->tacts * params->measure; else // na podstawie podanego czasu nFrames = params->tempo * params->pdur / 60; NEXTPATTERN(); // goc_saveXY(); for (i=0; i<nFrames; i++) { if ( imeasure ) { if ( params->flags & FLAG_PRINTCOUNT ) { goc_gotoxy(1, 5); printf("%s%s%s%d%s", GOC_STRING_YELLOW, prevString, GOC_STRING_BWHITE, imeasure + 1, GOC_STRING_YELLOW); prevString = goc_stringAddInt(prevString, imeasure+1); prevString = goc_stringAdd(prevString, " .. "); fflush(stdout); } if ( playedPattern == '.' ) ao_play(aodev, params->pBeat[BEAT_BASE].pFrame, params->pBeat[BEAT_BASE].nFrame); else ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame); NEXTPATTERN(); } else { if ( params->flags & FLAG_PRINTCOUNT ) { goc_gotoxy(1, 5); printf("%s%s", GOC_STRING_YELLOW, prevString); goc_gotoxy(1, 5); printf("%s%d%s", GOC_STRING_BWHITE, imeasure + 1, GOC_STRING_YELLOW); prevString = goc_stringFree(prevString); prevString = goc_stringAddInt(prevString, imeasure+1); prevString = goc_stringAdd(prevString, " .. "); fflush(stdout); } if ( playedPattern == '.' ) ao_play(aodev, params->pBeat[BEAT_ACCENT].pFrame, params->pBeat[BEAT_ACCENT].nFrame); else ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame); NEXTPATTERN(); } if ( (iinter = params->inter) ) { while ( iinter-- ) { if ( params->flags & FLAG_PRINTCOUNT ) { goc_gotoxy(1, 5); printf("%s%s%si%s", GOC_STRING_YELLOW, prevString, GOC_STRING_WHITE, GOC_STRING_YELLOW); prevString = goc_stringAdd(prevString, "i .. "); fflush(stdout); } if ( playedPattern == '.' ) ao_play(aodev, params->pBeat[BEAT_INTER].pFrame, params->pBeat[BEAT_INTER].nFrame); else ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame); NEXTPATTERN(); } } imeasure++; imeasure %= params->measure; } if ( params->flags & FLAG_PRINTCOUNT ) { goc_gotoxy(1, 5); printf("%s%s", GOC_STRING_YELLOW, prevString); } prevString = goc_stringFree(prevString); } printf("%s\nFinish\n", GOC_STRING_WHITE); if ( params->tacts ) { GOC_BINFO("Played %d frames in %d tacts", i, params->tacts); } else { GOC_BINFO("Played %d frames in %d seconds", i, params->pdur); } endProgram(0); return 0; }
// TODO : random landMass from min to max // TODO : putting next landMass level for height static void civGeneration(GOC_HANDLER mapa, int numStartPoints, int minLM, int maxLM, int MINLEVEL, int NEWLEVEL) { // int MINLEVEL=0; // int NEWLEVEL=1; int type = 0; stChange point; point.x = 0; point.y = 0; point.v = 0; stChange** pSet = NULL; int nSet = 0; int landMass; int svStartPoints = numStartPoints; int createdLandMass; GOC_BINFO("Start civ generation system [numStartPoint: %d, minLandMass: %d, maxLandMass: %d, level: %d]", numStartPoints, minLM, maxLM, NEWLEVEL); if ( MINLEVEL >= 10 ) return; if ( numStartPoints <= 0 ) return; if ( maxLM <= 0 ) return; while (numStartPoints--) { GOC_BDEBUG("Number of start points %d", numStartPoints); // inicjowanie do kolejnej iteracji tworzenia masy ladowej type = 0; landMass = minLM + goc_random(maxLM-minLM); createdLandMass = 0; GOC_BINFO("Generated landmass: %d", landMass); if ( nSet ) { GOC_DEBUG("Clear set"); int i; for ( i=0; i<nSet; i++ ) free(pSet[i]); pSet = goc_tableClear(pSet, &nSet); } while ( landMass ) { GOC_BDEBUG("Landmass to generate %d", landMass); // random new point if ( randomPoint(&point, type, MINLEVEL, mapa) ) { GOC_BDEBUG("Setting a point (%d,%d,%d)", point.x, point.y, NEWLEVEL); pSet = goc_tableAdd(pSet, &nSet, sizeof(void*)); pSet[nSet-1] = mallocPoint(point.x, point.y, NEWLEVEL); goc_maparawSetPoint(mapa, point.x, point.y, NEWLEVEL); createdLandMass++; } landMass--; while ( nSet ) { // random point from set int randp = goc_random(nSet); int x, y; type = 1; // neighbour // check a point has any free neighbour x = pSet[randp]->x; y = pSet[randp]->y; if ( ( (x+1 < context.configuration.maxx) && (goc_maparawGetPoint(mapa, x+1, y) <= MINLEVEL) ) || ( (y+1 < context.configuration.maxy) && (goc_maparawGetPoint(mapa, x, y+1) <= MINLEVEL )) || ( (y > 0) && (goc_maparawGetPoint(mapa, x, y-1) <= MINLEVEL) ) || ( (x > 0) && (goc_maparawGetPoint(mapa, x-1, y) <= MINLEVEL) ) ) { point.x = x; point.y = y; point.v = pSet[randp]->v; GOC_BDEBUG("Find point in set (%d,%d,%d)", point.x, point.y, point.v); break; } else { GOC_DEBUG("Remove point from set"); free(pSet[randp]); pSet = goc_tableRemove(pSet, &nSet, sizeof(void*), randp); } } // check, if there are any points in set if ( !nSet ) break; } GOC_BINFO("Created landmass: %d", createdLandMass); } civGeneration( mapa, svStartPoints, //-svStartPoints/20, minLM-minLM*precentageCut[MINLEVEL]/10, maxLM-maxLM*precentageCut[MINLEVEL]/10, MINLEVEL+1, NEWLEVEL+1); /* pStartPoint = randomStartPoints(&nStartPoint, numStartPoints); for (i=0; i<nStartPoint; i++) { goc_maparawSetPoint(mapa, pStartPoint[i]->x, pStartPoint[i]->y, 1); } */ }